ListBox Menu in Windows Phone 7
Howdy, I want to make a dynamically filled Menu in Windows Phone 7. I thought that a listbox would be the perfect fit for that. However, I cannot get the "selectedValue" once the user interacts with the listbox - hence I cannot give any information to the navigationhandler.
How can I create a ListBox whose Listbox Items are created dynamically and navigate the User on click to the same page b开发者_StackOverflow社区ut with different parameters e.g.
\informations.xam?id=2
Not that long ago I wrote an WP7 application and I used something like this:
private void CategoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CategoryList.SelectedIndex == -1) return;
string id = (CategoryList.SelectedItem as DepartmentViewModel).ID;
NavigationService.Navigate(new Uri("/Views/CatalogueBrowser/CategoriesPage.xaml?deptId=" + id, UriKind.Relative));
CategoryList.SelectedIndex = -1;
}
Basically, I set my listbox's itemssource to an observable collection of particular view models, then you just access the selected view model object using the SelectedItem property of the listbox.
Create a new "Windows Phone Databound Application" and the boilerplate code generated as part of the project will show you how to do this.
精彩评论