当前位置: 首页>>代码示例>>C#>>正文


C# ContextMenu.TranslatePoint方法代码示例

本文整理汇总了C#中System.Windows.Controls.ContextMenu.TranslatePoint方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.TranslatePoint方法的具体用法?C# ContextMenu.TranslatePoint怎么用?C# ContextMenu.TranslatePoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.ContextMenu的用法示例。


在下文中一共展示了ContextMenu.TranslatePoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateGraphCanvasContextMenu

        private ContextMenu CreateGraphCanvasContextMenu()
        {
            ContextMenu result = new ContextMenu();

            MenuItem menuItemAddActionNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Actions-tool-animator-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Action", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddActionNode.Click += delegate {
                AddNode("Action", result, delegate {
                    ActionNodeConfiguration newActionNode = new ActionNodeConfiguration();
                    #region Add a default action
                    ActionType actionType = ConfigManager.Configuration.GetActionTypes().First();
                    ActionConfiguration action = new ActionConfiguration(actionType.Name) {
                        Configuration = new SerializableXDocument(new XDocument(new XElement(XName.Get("objectConfig"))))
                    };
                    newActionNode.Actions.Add(action);
                    #endregion
                    return newActionNode;
                });
            };

            MenuItem menuItemAddCbrNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/nfs-unmount-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "CBR", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddCbrNode.Click += delegate {
                AddNode("CBR", result, delegate { return new CbrNodeConfiguration(); });
            };

            MenuItem menuItemAddTerminatorNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Button-exit-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Terminator", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddTerminatorNode.Click += delegate {
                Point menuLocationOnCanvas = result.TranslatePoint(new Point(), graphCanvas.Canvas);
                AddNode("Terminator", result, delegate { return new TerminatorNodeConfiguration(); });
            };

            MenuItem menuItemAdd = new MenuItem {
                Header = new TextBlock { Text = "Add node...", FontSize = 14 }  
            };
            menuItemAdd.Items.Add(menuItemAddActionNode);
            menuItemAdd.Items.Add(menuItemAddCbrNode);
            menuItemAdd.Items.Add(menuItemAddTerminatorNode);

            result.Items.Add(menuItemAdd);
            return result;
        }
开发者ID:bzamecnik,项目名称:XRouter,代码行数:49,代码来源:MessageflowConfigurationControl.xaml.cs

示例2: AddNode

        private void AddNode(string baseName, ContextMenu menu, Func<NodeConfiguration> nodeFactory)
        {
            NodeConfiguration node = nodeFactory();

            #region Set unique name
            int index = 1;
            string[] existingNames = Messageflow.Nodes.Select(n => n.Name).ToArray();
            while (existingNames.Contains(baseName + index.ToString())) {
                index++;
            }
            node.Name  = baseName + index.ToString();
            #endregion

            Point menuLocationOnCanvas = menu.TranslatePoint(new Point(), graphCanvas.Canvas);
            node.Location = menuLocationOnCanvas - graphCanvas.CanvasLocationOffset;
            Messageflow.Nodes.Add(node);
            MessageflowGraphPresenter.RaiseGraphChanged();

            ThreadUtils.InvokeLater(TimeSpan.FromSeconds(0.5), delegate {
                NodeSelectionManager.SelectNode(node);
            });
        }
开发者ID:bzamecnik,项目名称:XRouter,代码行数:22,代码来源:MessageflowConfigurationControl.xaml.cs


注:本文中的System.Windows.Controls.ContextMenu.TranslatePoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。