Answer the question
In order to leave comments, you need to log in
How to make a dynamic menu in Windows Phone 7
In general, I decided to try myself in this business, to write a client for my site for the purpose of self-education. No monetization is foreseen
:) for example, I get a list of objects from the site. Then I want that when tapping on an object, a page with a description of the object opens.
So far I've done it like this:
XAML:
<ListBox HorizontalAlignment="Left" Margin="9,0,0,0" Name="listBox1" VerticalAlignment="Top" SelectionChanged="OnChange" ItemsSource="{Binding}" SelectionMode="Single" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="4">
<Image Source="{Binding Path=Logo}" Width="82" Height="62" Stretch="Fill" />
<StackPanel Margin="4,0,0,0">
<TextBlock Text="{Binding Path=Name}" TextWrapping="Wrap" TextTrimming="WordEllipsis" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Инвестиции от " TextWrapping="Wrap" />
<TextBlock Text="{Binding Path=Invest}" TextWrapping="Wrap" />
<TextBlock Text=" руб." TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
WITH#:
var searchResults = from result in resultXml.Descendants("fr")
select new FranchiseOnMain
{
// Get the Title, Description and Url values.
Logo = result.Element("logo").Value,
Name = result.Element("name").Value,
Id = result.Element("id").Value,
Invest = result.Element("invest").Value
};
listBox1.DataContext = searchResults;
Those. there is a listbox in which I load the data received from the server in xml format.
Now I need to tap on the listbox element to open another page with an extended description of this object.
I did it like this:
private void OnChange(object sender, SelectionChangedEventArgs e)
{
if (listBox1.SelectedItem != null)
{
TextBlock textblock1 = new TextBlock();
FranchiseOnMain fr = (FranchiseOnMain)listBox1.SelectedItem;
string uri = "/FranchisePage.xaml?id=" + fr.Id + "&name=" + fr.Name;
NavigationService.Navigate(new Uri(uri, UriKind.RelativeOrAbsolute));
listBox1.SelectedItem = null;
}
}
Those. after selecting an object, I open another page with a parameter using the navigation service, and reset the selection so that when I return back to the main page, nothing is selected in the listbox.
If the selection is not reset, then the problem arises that when I return to the list of objects, I cannot get to the same one again because it is already selected in the listbox and SelectionChanged does not work.
But I don't like this solution, I want to do it right. How to do it right? Do I need to use not a listbox, but some other control? Are there other controls that can automatically load a collection of objects or will it be necessary to do this manually? In principle, doing it manually is not a problem if you tell me which control to set to navigate between pages (with a normal click animation).
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question