コード例 #1
0
        private void ListView_ContextRequested(UIElement sender, ContextRequestedEventArgs e)
        {
            // Walk up the tree to find the ListViewItem.
            // There may not be one if the click wasn't on an item.
            var requestedElement = (FrameworkElement)e.OriginalSource;

            while ((requestedElement != sender) && !(requestedElement is ListViewItem))
            {
                requestedElement = (FrameworkElement)VisualTreeHelper.GetParent(requestedElement);
            }
            if (requestedElement != sender)
            {
                // The context menu request was indeed for a ListViewItem.
                var   model = (SampleDataModel)ItemListView.ItemFromContainer(requestedElement);
                Point point;
                if (e.TryGetPosition(requestedElement, out point))
                {
                    rootPage.NotifyUser($"Showing flyout for {model.Title} at {point}", NotifyType.StatusMessage);
                    sharedFlyout.ShowAt(requestedElement, point);
                }
                else
                {
                    // Not invoked via pointer, so let XAML choose a default location.
                    rootPage.NotifyUser($"Showing flyout for {model.Title} at default location", NotifyType.StatusMessage);
                    sharedFlyout.ShowAt(requestedElement);
                }

                e.Handled = true;
            }
        }
コード例 #2
0
        private SampleDataModel GetDataModelForCurrentListViewFlyout()
        {
            // Obtain the ListViewItem for which the user requested a context menu.
            var listViewItem = SharedFlyout.Target;

            // Get the data model for the ListViewItem.
            return((SampleDataModel)ItemListView.ItemFromContainer(listViewItem));
        }