Пример #1
0
        private void TreeView_ContextRequested(UIElement sender, ContextRequestedEventArgs e)
        {
            var datacontext = (e.OriginalSource as FrameworkElement)?.DataContext;

            if (datacontext != null && (sender as FrameworkElement).DataContext != datacontext)
            {
                var args = new ContextMenuRequestedEventArgs(datacontext);
                ContextMenuRequested?.Invoke(this, args);
                if (args.MenuItems != null && args.MenuItems.Count > 0)
                {
                    var menu = new MenuFlyout();
                    foreach (var item in args.MenuItems)
                    {
                        menu.Items.Add(item);
                    }
                    if (e.TryGetPosition(e.OriginalSource as UIElement, out Point p))
                    {
                        menu.ShowAt(e.OriginalSource as UIElement, p);
                    }
                    else
                    {
                        menu.ShowAt(e.OriginalSource as UIElement, new FlyoutShowOptions()
                        {
                            Placement = FlyoutPlacementMode.Auto
                        });
                    }
                    e.Handled = true;
                }
            }
        }
Пример #2
0
        private void TableOfContents_ContextMenuRequested(object sender, ContextMenuRequestedEventArgs e)
        {
            if (e.TreeViewNode is KmlNode node)
            {
                if (node.Viewpoint != null)
                {
                    var item = new MenuFlyoutItem()
                    {
                        Text = "Fly to"
                    };
                    Camera camera = null;
                    if (node.Viewpoint.Type == KmlViewpointType.LookAt)
                    {
                        camera = new Camera(node.Viewpoint.Location, node.Viewpoint.Range, node.Viewpoint.Heading, node.Viewpoint.Pitch, node.Viewpoint.Roll);
                    }
                    else
                    {
                        camera = new Camera(node.Viewpoint.Location, node.Viewpoint.Heading, node.Viewpoint.Pitch, node.Viewpoint.Roll);
                    }

                    item.Click += (s, e2) => sceneView.SetViewpointAsync(new Viewpoint(node.Viewpoint.Location, camera));
                    e.MenuItems.Add(item);
                }
                else if (node is KmlPlacemark kp && kp.Geometry != null)
                {
                    var item = new MenuFlyoutItem()
                    {
                        Text = "Fly to"
                    };
                    item.Click += (s, e2) => sceneView.SetViewpointAsync(new Viewpoint(kp.Geometry));
                    e.MenuItems.Add(item);
                }
                if (node is KmlNetworkLink knl)
                {
                    var item = new MenuFlyoutItem()
                    {
                        Text = "Refresh"
                    };
                    item.Click += (s, e2) => knl.Refresh();
                    e.MenuItems.Add(item);
                    if (knl.RefreshMode == KmlRefreshMode.OnInterval)
                    {
                        item = new MenuFlyoutItem()
                        {
                            Text = "Disable autorefresh"
                        };
                        item.Click += (s, e2) => knl.RefreshMode = KmlRefreshMode.OnChange;
                        e.MenuItems.Add(item);
                    }
                }
                else if (node is KmlTour tour)
                {
                    var item = new MenuFlyoutItem()
                    {
                        Text = tour.TourStatus == KmlTourStatus.Playing ? "Stop" : "Play"
                    };
                    item.Click += (s, e2) => ToggleTour(tour);
                    e.MenuItems.Add(item);
                }
            }
        }