我正在使用 GridView 构建 Windows 8 Metro 应用程序(C#、XAML),并且我想在用户单击的 GridViewItem 附近显示一个弹出窗口。我计划通过单击事件参数获取 GridViewItem UIElement 并使用它的坐标来确定放置我的弹出窗口的位置。
但是,我还没有找到一种方法来获取对被点击的实际 GridViewItem UIElement 的引用!我在下面尝试过的事件似乎只通过它们的 EventArgs 公开 DataContext,而不是实际的 UIElement:
object sender // is the GridView
ItemClickEventArgs.ClickedItem // is the DataContext of the GridViewItem
ItemClickEventArgs.OriginalSource // is the GridView
SelectionChangedEventArgs.OriginalSource // is null
SelectionChangedEventArgs.AddedItems.First() // is the DataContext of the GridViewItem
如果重要的话,我的 GridView.ItemSource 是一个 CollectionViewSource,它的 Source 绑定到一个视图模型的集合。
是否可以通过我忽略的某些事件来获取单击的 GridViewItem?如果不是,我应该从什么角度来解决它?我至少可以通过 PointerPressed 事件获得相对于 GridView 的点击坐标,并查看我可以做些什么来以这种方式定位项目,但真的希望我不必走那条路。