我的要求是我想用右键/长螺纹选择一个项目,并从应用程序栏按钮和鼠标左键点击相应采取行动/ TAP要我重定向到下一个XAML页面。我遇到的问题是右键单击,我无法检测到已点击了哪些GridView项目,如何将其添加到SelectedItem。
我所做的是,我在GridView的DataTemplate中引入了额外的Grid。在此网格中,我添加了RightTapped事件。
的示例代码片段是
<GridView x:Name="ItemGridView"
ItemsSource="{Binding Source={StaticResource ItemsViewSource}}"
IsItemClickEnabled="True"
SelectionMode="Single" ItemClick="ItemGridView_ItemClick"
SelectionChanged="ItemGridView_SelectionChanged">
<GridView.ItemTemplate>
<DataTemplate>
<Grid RightTapped="Grid_RightTapped">
<Border Background="White" BorderThickness="0" Width="210" Height="85">
<TextBlock Text="{Binding FileName}" />
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
事件名称是Grid_RightTapped。这帮助我检测到从哪个GridViewItem获得长按/右键单击。
代码隐藏的是这样的:
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
Song selectedItem = (sender as Grid).DataContext as Song;
//the above line will get the exact GridViewItem where the User Clicked
this.ItemGridView.SelectedItem = selectedItem;
//the above line will add the item into SelectedItem and hence, I can take any action after this which I require
}
}
,我们正在做这件事的办法是,因为现在我们可以用鼠标右键单击添加单击项目到GridView的的SelectedItem原因。现在在UWP中,单击的项目仅通过左键单击添加到SelectedItem中。通过左键单击,我可以使用ItemClick事件导航到另一个页面。
我尝试过使用RightTapped,但它没有给我哪个项目已被选中在GridView中。并且需要对新设计进行思考。我的右键单击选择项目,并显示不同的应用程序栏按钮根据哪个类别被点击和左键单击/点击导航。我可以使用哪种控制/事件,这将使我能够提供这两种功能。 – Aakansha