我使用windows 8项目模板显示网格,然后用我的数据填充它。然后每个网格项将我带到指定的页面。如何提取哪个网格项元素,以便我可以将用户带到适当的页面?这就是我填充数据的方式:
private ObservableCollection<MenuItem> MenuItems = new ObservableCollection<MenuItem>();
内部onNavigatedTo()。一切正常
MenuItems.Add(new MenuItem
{
Title = "Tips",
Subtitle = "Useful information that helps you to become lucid",
Image = new BitmapImage(new Uri("ms-appx:///Images/tips.png",
UriKind.RelativeOrAbsolute))
});
MenuItems.Add(new MenuItem
{
Title = "FAQ",
Subtitle = "Most commonly asked questions",
Image = new BitmapImage(new Uri("ms-appx:///Images/faq.png",
UriKind.RelativeOrAbsolute))
});
itemGridView.ItemsSource = MenuItems;
itemListView.ItemsSource = MenuItems;
}
答案 0 :(得分:1)
您在GridView和ListView中填充数据。这些控件具有几乎相同的相互作用。在Xaml页面中,修改Gridview以至少具有以下属性:
<GridView x:Name="itemGridView"
SelectionMode="None"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"/>
和ListView:
<ListView x:Name="itemListView"
SelectionMode="None"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"/>
并将“ItemView_ItemClick”事件添加到Xaml.cs以将用户带到相应的页面。
有关更多信息:MSDN上的How to change the interaction mode (Windows Store apps using C#/VB/C++ and XAML)