I want to put two Buttons in my MapControl, one to zoom in, and other to zoom out, here's my CS file with a code,what i did here i use the
MapControl1.ZoomLevel = 15; , but how i can put this inside a button?
public async void mapas2()
{
Geolocator geolocator = new Geolocator();
Geoposition geoposition = null;
try
{
geoposition = await geolocator.GetGeopositionAsync();
}
catch (Exception ex)
{
MessageDialog ms = new MessageDialog("Erro GPS, Por favor, acesse as configurações de seu Windows Phone," + Environment.NewLine +
"na opção LOCALIZAÇÃO e habilite o Serviço de Localização");
ms.ShowAsync();
}
MapControl1.Center = geoposition.Coordinate.Point;
MapControl1.ZoomLevel = 15;
MapIcon mapIcon = new MapIcon();
mapIcon.NormalizedAnchorPoint = new Point(0.25, 0.9);
mapIcon.Location = geoposition.Coordinate.Point;
mapIcon.Title = "Você está aqui....";
MapControl1.MapElements.Add(mapIcon);
}
You can place these buttons with your map control in one Grid in XAML, so the will look like they're on the map.
Example:
<Grid>
<Maps:MapControl />
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Orientation="Horizontal"
Margin="24">
<Button Content="+"
Margin="12"
MinWidth="40" />
<Button Content="-"
Margin="12"
MinWidth="40" />
</StackPanel>
</Grid>
Just few more lines to Łukasz Rejman answer
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom" Orientation="Horizontal" Margin="15">
<Button x:Name="ZooOut" Content="-" Margin="5" MinWidth="60" MinHeight="60" Tapped="ZooOut_Tapped" />
<Button x:Name="ZoomIn" Content="+" Margin="5" MinWidth="60" MinHeight="60" Tapped="ZoomIn_Tapped" />
</StackPanel>
Button Tapped Event:
private void ZoomIn_Tapped(object sender, TappedRoutedEventArgs e)
{
if (CustomMapControl.ZoomLevel < 20)
{
if (CustomMapControl.ZoomLevel > 19)
CustomMapControl.ZoomLevel = 20;
else
CustomMapControl.ZoomLevel++;
}
}
private void ZooOut_Tapped(object sender, TappedRoutedEventArgs e)
{
if (CustomMapControl.ZoomLevel > 1)
{
if (CustomMapControl.ZoomLevel < 2)
CustomMapControl.ZoomLevel = 1;
else
CustomMapControl.ZoomLevel--;
}
}
Related
Sorry for the silly question.I even did not understand what should be given as title to this question.
I have 3 buttons and when I click them listboxes should be displayed.
And if I select an item in listbox it should be navigated and start playing.
When I click a button listbox is displaying and when an item is selected it is navigating to to other page and playing.After performing selection changed if I click any button I was getting error like
A first chance exception of type 'System.NullReferenceException' occurred in tori.dll
An unhandled exception of type 'System.NullReferenceException' occurred in tori.dll
Archieves .xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,-951,0">
<Button Name="btn1" Click="btn1_Click" Content="Daily" HorizontalAlignment="Left" Margin="0,88,0,0" VerticalAlignment="Top" Width="127" Height="72"/>
<Button Name="btn2" Click="btn2_Click" Content="Weekly" HorizontalAlignment="Left" Margin="132,88,0,0" VerticalAlignment="Top" Height="72" Width="140"/>
<Button Name="btn3" Click="btn3_Click" Content="CurrentMonth" HorizontalAlignment="Left" Margin="277,88,0,0" VerticalAlignment="Top" Height="72" Width="169"/>
<ListBox x:Name="itemsList" Margin="0,225,945,0"
SelectionChanged="itemsList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="130">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image delay:LowProfileImageLoader.UriSource="{Binding ThumbnailUrl}"
Grid.Column="0"
Width="500"
Height="125"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="6"/>
<StackPanel Margin="10,20,0,0"
Grid.Column="1"
Height="60"
Orientation="Horizontal"
VerticalAlignment="Center">
<TextBlock Text="{Binding title}"
FontSize="40" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Archieves.xaml.cs:
namespace tori
{
public partial class Archieves : PhoneApplicationPage
{
public Archieves()
{
InitializeComponent();
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
WebClient downloader = new WebClient();
Uri uri = new Uri(" http://www.toucheradio.com/RSSFeed/rssDaily.php ", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ChannelDownloaded);
downloader.DownloadStringAsync(uri);
}
void ChannelDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
var queue = from item in document.Descendants("item")
select new Item
{
title = item.Element("title").Value
,
link = item.Element("link").Value
,
pubDate = item.Element("pubDate").Value
,
ThumbnailUrl = item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value
,
};
itemsList.ItemsSource = queue;
}
}
private void btn2_Click(object sender, RoutedEventArgs e)
{
WebClient downloader = new WebClient();
Uri uri = new Uri(" http://www.toucheradio.com/RSSFeed/rssWeekly.php ", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Channel1Downloaded);
downloader.DownloadStringAsync(uri);
}
void Channel1Downloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
var queue = from item in document.Descendants("item")
select new Item
{
title = item.Element("title").Value
,
link = item.Element("link").Value
,
pubDate = item.Element("pubDate").Value
,
ThumbnailUrl = item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value
,
};
itemsList.ItemsSource = queue;
}
}
private void btn3_Click(object sender, RoutedEventArgs e)
{
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.toucheradio.com/RSSFeed/rssMonthly.php ", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Channel2Downloaded);
downloader.DownloadStringAsync(uri);
}
void Channel2Downloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
var queue = from item in document.Descendants("item")
select new Item
{
title = item.Element("title").Value
,
link = item.Element("link").Value
,
pubDate = item.Element("pubDate").Value
,
ThumbnailUrl = item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value
,
};
itemsList.ItemsSource = queue;
}
}
private void itemsList_SelectionChanged(Object sender, SelectionChangedEventArgs e)
{
var app = App.Current as App;
app.selectedItem = (Item)itemsList.SelectedItem;
this.NavigationService.Navigate(new Uri("/Details.xaml", UriKind.Relative));
}
Item.cs:
namespace tori
{
public class Item
{
public string title { get; set; }
public string ThumbnailUrl { get; set; }
public string link { get; set; }
public string pubDate { get; set; }
}
}
Details.xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid Height="617" VerticalAlignment="Top" Margin="-27,96,0,0">
<Image x:Name="ThumbnailUrl"
Width="279"
Height="421"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0,-29,204,225" />
<Image x:Name="Image1" Tap="Image1_Tap" Margin="46,430,354,92" Source="/Images/pausebutton.png"/>
<TextBlock x:Name="title" FontSize="30" TextWrapping="Wrap" Margin="284,57,-50,436" />
<TextBlock x:Name="pubDate" FontSize="25" Margin="284,186,10,363" />
<MediaElement x:Name="MediaElement1" AutoPlay="True" Margin="0,397,20,0" Height="94" VerticalAlignment="Top" />
Details.xaml.cs:
namespace tori
{
public partial class Details : PhoneApplicationPage
{
Item item;
public Details()
{
InitializeComponent();
var app = App.Current as App;
item = app.selectedItem;
title.Text = item.title;
pubDate.Text = item.pubDate;
ThumbnailUrl.Source = new BitmapImage(new Uri(item.ThumbnailUrl, UriKind.RelativeOrAbsolute));
string s = item.link;
string url = s.Replace("archivesplayer", "hostArchivesURLForMobile");
WebClient downloader = new WebClient();
Uri uri = new Uri(url,UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Channel3Downloaded);
downloader.DownloadStringAsync(uri);
}
void Channel3Downloaded(object sender, DownloadStringCompletedEventArgs e)
{
var textData = (string)e.Result;
Regex urlRegex = new Regex("<td height=\"25\" align=\"center\">(?<url>.*)</td>");
MatchCollection mc = urlRegex.Matches(textData);
string url = "";
if (mc.Count > 0)
{
url = mc[0].Groups["url"].Value;
MediaElement1.Source = new Uri(url, UriKind.Absolute);
MediaElement1.Play();
}
}
}
}
After performing selecting item if I click a button I was getting error in this line
title.Text = item.title;
Can anybody please tell me how can I overcome this null exception.When I click on a button selection changed event is raising instead of click event. I am unable to know the reason for this.
Please anybody help me with this.
many Thanks in advance.
When you change the ItemsSource, the SelectionChanged event is raised. I think whenever you change the ItemsSource, the selection is reset (that is - set to null (none selected)). And that's how it should be, otherwise an item that's not in the ItemsSource could be the SelectedItem which is just wrong.
Now, to fix your issue, just check if SelectedItem != null in itemsList_SelectionChanged method.
Something else about your code: the methods btn1_Click, btn2_Click and btn3_Click seem to only have minor differences, so you could put most of the code in one method and just pass it the url. That's even more important for the ChannelDownloaded methods (as they are much longer). Basically you want to reuse code as much as possible. That makes the code easier to read (as it's not 10 pages, but one, so to speak), and easier to maintain (if there's an error - you only need to fix it in one place).
I am working on Windows Phone 8,since I am new on this technology, I need a help regarding camera. I am working on camera test, I got a NotSupportedException (Specified Method not Supported) kind of exception on back key press event. If I pressed back key immediately after initialization of camera then it will crash the application. I didn't get any source related with this issue.
so, can anyone help me to figure out this problem ?
Thanks
Xaml for your page, might be like this
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform x:Name="viewfinderBrushTransform" CenterX=".5" CenterY=".5" Rotation="90" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Canvas.Background>
<StackPanel Name="stkLoading" Height="50" Canvas.Top="245" Visibility="Collapsed">
<TextBlock Foreground="Red" Text="Scanning.." HorizontalAlignment="Center"/>
<ProgressBar IsIndeterminate="True" Width="480"/>
</StackPanel>
</Canvas>
Cs Code
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
//make some navigation like this
NavigationService.Navigate(new Uri("/View/EditDocument.xaml, UriKind.RelativeOrAbsolute));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
try
{
InitializeCamera();
}
catch (Exception ex)
{
MessageBox.Show("Problem occured in camera declaration.");
}
}
public void InitializeCamera()
{
try
{
if (myCamera != null)
{
myCamera.AutoFocusCompleted -= OnCameraAutoFocusCompleted;
myCamera.Initialized -= myCamera_Initialized;
myCamera.CaptureCompleted -= new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);
myCamera.CaptureImageAvailable -= new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(camera_CaptureImageAvailable);
}
viewfinderBrush = null;
canvasCameraView.Background = null;
myCamera = null;
bdrInitializingCamera.Visibility = Visibility.Visible;
viewfinderBrush = new VideoBrush();
CompositeTransform ct = new CompositeTransform();
ct.CenterX = .5;
ct.CenterY = .5;
ct.Rotation = 90;
viewfinderBrush.RelativeTransform = ct;
canvasCameraView.Background = viewfinderBrush;
myCamera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(myCamera);
myCamera.Initialized += myCamera_Initialized;
myCamera.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);
myCamera.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(camera_CaptureImageAvailable);
}
catch (Exception ex)
{
if (MessageBox.Show("An error occured in camera initialization, please try again. note \n " + ex.Message) == MessageBoxResult.OK)
{
//Make a navigation
}
}
}
So basically this is the situation. I have a longlistselector that shows data (say, a list of cars):
<phone:LongListSelector x:Name="list" ItemsSource="{Binding CarList}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Click="DeleteMenuItem_Click" Header="delete"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding SomeText}">
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
And then this is how I handle the deletion:
private void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
{
Car data = (sender as MenuItem).DataContext as Car;
using (var db = new SQLiteConnection(App.DBpath))
{
var existing = db.Query<Feed>("select * from Cars where Id = " + data.Id.ToString()).FirstOrDefault();
if (existing != null)
{
db.RunInTransaction(() =>
{
db.Delete(existing);
});
App.ViewModel.loadCarData();
}
}
}
Now the issue is that after deleting few, the context menu starts to give old selection and does not update which makes var existing = db.Query<Feed>("select * from Cars where Id = " + data.Id.ToString()).FirstOrDefault(); return null obviously because it has been already deleted from database. Any idea how to fix this?
Probably this issue.
private void ContextMenu_Unload(object sender, RoutedEventArgs e)
{
ContextMenu conmen = (sender as ContextMenu);
conmen.ClearValue(FrameworkElement.DataContextProperty);
}
I had developed application which plays videos using MediaElement with remote url. Everything works fine videos are also playing nicely.
But the problem I am facing is if user is playing video and user touches windows button on phone. Then my app goes to background and home screen is displayed. now on home screen user touches back button. My app is brought to foreground and video starts loading from beginning. Is there anyway by which I can pause mediaelement so that when user comes back to my app video gets resumed.
One more thing is I can not user MediaLauncher since I want to log some events when user interacts with mediacontrols such as play/pause.
Kindly requesting you all to guide me in this scenario.
Thank You.
you can resume your application via ActivationPolicy attribute to the DefaultTask element inActivationPolicy attribute to the DefaultTask element in WMAppManifest.xml and set the value to “Resume”. For this task, you need to edit the app manifest directly instead of using the manifest editor. To do this, right-click WMAppManifest.xml, click Open with, and then choose XML (Text) Editor.
For Resume can be enabled for XAML apps, Direct3D apps, and Direct3D with XAML apps. The following examples show how the DefaultTask element will look for a XAML app and for a Direct3D app.
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"/>
<DefaultTask Name="_default" ImagePath="PhoneDirect3DApp1.exe" ImageParams="" ActivationPolicy="Resume"/>
app resume for Windows Phone 8
app resume backstack sample
If this will not help you than you can manual paly and stop your video pleyer like bellow code
XAML
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="0.90*"/>
<RowDefinition Height="0.10*"/>
</Grid.RowDefinitions>
<SSME:SmoothStreamingMediaElement x:Name="video" Grid.Row="0" />
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button x:Name="PlayButton" Width="150" Click="PlayButton_Click" Loaded="PlayButton_Loaded"/>
<Button x:Name="StopButton" Content="Stop" Width="100" Click="StopButton_Click" />
<TextBlock x:Name="status"/>
<TextBlock x:Name="currentBitrate"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
</Grid>
C# code:
public partial class VIdeoStraming : PhoneApplicationPage
{
string VideoUrl,StreamingUrl;
public VIdeoStraming()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
VideoUrl = this.NavigationContext.QueryString["parameter0"];
string Manifest="/Manifest";
StreamingUrl = VideoUrl + Manifest;
}
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
//Monitor the state of the content to determine the right action to take on this button being clicked
//and then change the text to reflect the next action
switch (video.CurrentState)
{
case SmoothStreamingMediaElementState.Playing:
video.Pause();
PlayButton.Content = "Play";
break;
case SmoothStreamingMediaElementState.Stopped:
case SmoothStreamingMediaElementState.Paused:
video.Play();
PlayButton.Content = "Pause";
break;
}
}
private void PlayButton_Loaded(object sender, RoutedEventArgs e)
{
switch (video.AutoPlay)
{
case false:
PlayButton.Content = "Play";
break;
case true:
PlayButton.Content = "Pause";
break;
}
}
private void StopButton_Click(object sender, RoutedEventArgs e)
{
//This should simply stop the playback
video.Stop();
//We should also reflect the chang on the play button
PlayButton.Content = "Play";
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
video.CurrentStateChanged += new RoutedEventHandler(video_CurrentStateChanged);
video.PlaybackTrackChanged += new EventHandler<Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs>(video_PlaybackTrackChanged);
//video.SmoothStreamingSource = new Uri("http://64.120.251.114:1945/live/sharedobjects/layoutvideo/mp4:1311370468970.MP4/Manifest");
video.SmoothStreamingSource = new Uri(StreamingUrl);
video.ManifestReady += new EventHandler<EventArgs>(video_ManifestReady);
}
//when use in mobile device
void video_ManifestReady(object sender, EventArgs e)
{
SmoothStreamingMediaElement ssme = sender as SmoothStreamingMediaElement;
if (ssme == null)
{
return;
}
// Select the highest band of tracks which all have the same resolution.
// maxMobileBitrate depends on the encoding settings
const ulong maxMobileBitrate = 1000000;
foreach (SegmentInfo segment in ssme.ManifestInfo.Segments)
{
foreach (StreamInfo streamInfo in segment.AvailableStreams)
{
if (MediaStreamType.Video == streamInfo.Type)
{
List<TrackInfo> widestBand = new List<TrackInfo>();
List<TrackInfo> currentBand = new List<TrackInfo>();
ulong lastHeight = 0;
ulong lastWidth = 0;
ulong index = 0;
foreach (TrackInfo track in streamInfo.AvailableTracks)
{
index += 1;
string strMaxWidth;
string strMaxHeight;
// If can't find width/height, choose only the top bitrate.
ulong ulMaxWidth = index;
// If can't find width/height, choose only the top bitrate.
ulong ulMaxHeight = index;
// V2 manifests require "MaxWidth", while v1 manifests used "Width".
if (track.Attributes.TryGetValue("MaxWidth", out strMaxWidth) ||
track.Attributes.TryGetValue("Width", out strMaxWidth))
{
ulong.TryParse(strMaxWidth, out ulMaxWidth);
}
if (track.Attributes.TryGetValue("MaxHeight", out strMaxHeight) ||
track.Attributes.TryGetValue("Height", out strMaxHeight))
{
ulong.TryParse(strMaxHeight, out ulMaxHeight);
}
if (ulMaxWidth != lastWidth ||
ulMaxHeight != lastHeight)
{
// Current band is now finished, check if it is the widest.
// If same size, current band preferred over previous
// widest, because it will be of higher bitrate.
if (currentBand.Count >= widestBand.Count)
{
// A new widest band:
widestBand = currentBand;
currentBand = new List<TrackInfo>();
}
}
if (track.Bitrate > maxMobileBitrate)
{
break;
}
// Current track always gets added to current band.
currentBand.Add(track);
lastWidth = ulMaxWidth;
lastHeight = ulMaxHeight;
}
if (0 == widestBand.Count &&
0 == currentBand.Count)
{
// Lowest bitrate band is > maxMobileBitrate.
widestBand.Add(streamInfo.AvailableTracks[0]);
}
else if (currentBand.Count >= widestBand.Count)
{
// Need to check the last band which was constructed.
Debug.Assert(currentBand.Count > 0);
widestBand = currentBand; // Winner by default.
}
Debug.Assert(widestBand.Count >= 1);
streamInfo.RestrictTracks(widestBand);
}
}
}
}
void video_PlaybackTrackChanged(object sender, Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs e)
{
currentBitrate.Text = e.NewTrack.Bitrate.ToString();
}
void video_CurrentStateChanged(object sender, RoutedEventArgs e)
{
status.Text = video.CurrentState.ToString();
}
private void imghdrleft_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
NavigationService.GoBack();
}
private void imghdrright_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
NavigationService.Navigate(new Uri("/Planet41VIew/Settings.xaml", UriKind.RelativeOrAbsolute));
}
}
I'm getting data to create a Listbox like a blog with JSON from a webblog, I want to pass this data when you select one item, to another simple xaml page with the information of this news(Title, content and Image). How can I get all the values for a new page with the information of the selected Item of the list?
I have this code for the listBox:
<ListBox x:Name="NewsList" Margin="0,200,0,0" ItemsSource="{Binding Items}" SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17" Width="432" Height="100">
<!--Replace rectangle with image-->
<Image x:Name="Imagen" Height="100" Width="100" Margin="12,0,9,0">
<Image.Source>
<BitmapImage UriSource="{Binding LineThree}" />
</Image.Source>
</Image>
<StackPanel Width="311">
<TextBlock x:Name="Titulo" Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="18.667" FontFamily="Tahoma" Margin="12,0,12,6"/>
<TextBlock x:Name="Contenido" Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,0" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="16"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I get the values from the news here :
Items is the list where I add the values of the news(Title, content, and Image)
public void LoadData()
{
WebRequest.RegisterPrefix("http://automaticband.es/blog/", WebRequestCreator.ClientHttp);
Uri serviceUri = new Uri("http://automaticband.es/blog/?json=get_recent_post");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
try
{
Stream responseStream = e.Result;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Posts));
Posts response = (Posts)ser.ReadObject(responseStream);
if (response.posts != null && response.posts.Count > 0)
{
foreach (Post post in response.posts)
{
this.Items.Add(new ItemViewModel() { LineOne = post.title, LineTwo = post.excerpt,
LineThree = post.thumbnail});
}
}
}
catch (Exception x)
{
return;
}
this.IsDataLoaded = true;
}
}
Thank you
I found the solution here :
http://windowsphonegeek.com/articles/Windows-Phone-MVVM-Master---Details-Navigation-in-5-minutes
Easy way to pass data between pages with ItemViewModel.