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


C# Controls.ContextMenu类代码示例

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


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

示例1: CreateWidgetControl

        public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu)
        {
            var buttonHolder = widgetViewModel as EntityButtonWidgetViewModel;

            var ret = new FlexButton.FlexButton { DataContext = buttonHolder, ContextMenu = contextMenu, CommandParameter = buttonHolder };

            var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var captionBinding = new Binding("Settings.Caption") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var radiusBinding = new Binding("CornerRadius") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var buttonColorBinding = new Binding("ButtonColor") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var commandBinding = new Binding("ItemClickedCommand") { Source = buttonHolder, Mode = BindingMode.OneWay };
            var enabledBinding = new Binding("IsEnabled") { Source = buttonHolder, Mode = BindingMode.OneWay };
            var rotateTransform = new Binding("RotateTransform") { Source = buttonHolder, Mode = BindingMode.OneWay };

            ret.SetBinding(InkCanvas.LeftProperty, xBinding);
            ret.SetBinding(InkCanvas.TopProperty, yBinding);
            ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
            ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);
            ret.SetBinding(ContentControl.ContentProperty, captionBinding);
            ret.SetBinding(FlexButton.FlexButton.CornerRadiusProperty, radiusBinding);
            ret.SetBinding(FlexButton.FlexButton.ButtonColorProperty, buttonColorBinding);
            ret.SetBinding(ButtonBase.CommandProperty, commandBinding);
            ret.SetBinding(FrameworkElement.LayoutTransformProperty, rotateTransform);
            //ret.SetBinding(UIElement.IsEnabledProperty, enabledBinding);

            return ret;
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:30,代码来源:EntityButtonWidgetCreator.cs

示例2: CreateWidgetControl

        public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu)
        {
            var buttonHolder = widgetViewModel as TicketExplorerViewModel;

            var ret = new TicketExplorerView { DataContext = buttonHolder, ContextMenu = contextMenu };

            var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var radiusBinding = new Binding("CornerRadius") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var buttonColorBinding = new Binding("ButtonColor") { Source = buttonHolder, Mode = BindingMode.TwoWay };
            var enabledBinding = new Binding("IsEnabled") { Source = buttonHolder, Mode = BindingMode.OneWay };
            var transformBinding = new Binding("RenderTransform") { Source = buttonHolder, Mode = BindingMode.OneWay };

            ret.SetBinding(InkCanvas.LeftProperty, xBinding);
            ret.SetBinding(InkCanvas.TopProperty, yBinding);
            ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
            ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);
            //ret.SetBinding(FlexButton.FlexButton.CornerRadiusProperty, radiusBinding);
            //ret.SetBinding(FlexButton.FlexButton.ButtonColorProperty, buttonColorBinding);
            //ret.SetBinding(UIElement.RenderTransformProperty, transformBinding);
            //ret.SetBinding(UIElement.IsEnabledProperty, enabledBinding);

            return ret;
        }
开发者ID:yemreguney,项目名称:SambaPOS-3,代码行数:26,代码来源:TicketExplorerWidgetCreator.cs

示例3: GetContextMenu

        /// <summary>
        /// Returns a context menu containing commands with commandTags</summary>
        /// <param name="commandTags">Command tags for commands to include on menu</param>
        /// <returns>ContextMenu</returns>
        public ContextMenu GetContextMenu(IEnumerable<object> commandTags)
        {
            m_commandService.SuggestRequery();

            var menu = new ContextMenu();
            menu.SetResourceReference(ContextMenu.StyleProperty, Resources.MenuStyleKey);
            //menu.Style = (Style)Application.Current.FindResource(Resources.MenuStyleKey);

            // Generate view model
            List<ICommandItem> commands = new List<ICommandItem>();
            foreach (var tag in commandTags)
            {
                var command = m_commandService.GetCommand(tag);
                if (command != null)
                {
                    if (!AutoCompact || ((ICommand)command).CanExecute(command))
                        commands.Add(command);
                }
            }
            commands.Sort(new CommandComparer());

            var dummyRootMenu = new Sce.Atf.Wpf.Models.Menu(null, null, null, null, null);
            foreach (var command in commands)
                MenuUtil.BuildSubMenus(command, dummyRootMenu);

            MenuUtil.InsertGroupSeparators(dummyRootMenu);
            menu.ItemsSource = dummyRootMenu.ChildCollection;

            return menu;
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:34,代码来源:ContextMenuService.cs

示例4: SetupContextMenu

        private void SetupContextMenu()
        {
            var ctm = new ContextMenu {Background = Brushes.DarkGray};
            var miSmall = new MenuItem();
            miSmall.Click += ChangetoSmall;
            miSmall.Header = "Small";
            miSmall.Foreground = Brushes.White;
            var miNormal = new MenuItem();
            miNormal.Click += ChangetoNormal;
            miNormal.Header = "Normal";
            miNormal.Foreground = Brushes.White;
            var miLarge = new MenuItem();
            miLarge.Click += ChangetoLarge;
            miLarge.Header = "Large";
            miLarge.Foreground = Brushes.White;
            var miChangeSize = new MenuItem
            {
                Header = "Change Size",
                Foreground = Brushes.White
            };
            miChangeSize.Items.Add(miSmall);
            miChangeSize.Items.Add(miNormal);
            miChangeSize.Items.Add(miLarge);
            ctm.Items.Add(miChangeSize);

            ContextMenu = ctm;
        }
开发者ID:Neakas,项目名称:ProjectSWN,代码行数:27,代码来源:Token.cs

示例5: CreateWidgetControl

        public FrameworkElement CreateWidgetControl(IDiagram widget, ContextMenu contextMenu)
        {
            var viewModel = widget as EntityGridWidgetViewModel;
            Debug.Assert(viewModel != null);

            if (widget.DesignMode)
            {
                viewModel.RefreshSync();
                foreach (var entityScreenItemViewModel in viewModel.ResourceSelectorViewModel.EntityScreenItems)
                {
                    entityScreenItemViewModel.IsEnabled = false;
                }

            }

            var ret = new EntitySelectorView(viewModel.ResourceSelectorViewModel) { DataContext = viewModel.ResourceSelectorViewModel, ContextMenu = contextMenu, Tag = widget };

            var heightBinding = new Binding("Height") { Source = viewModel, Mode = BindingMode.TwoWay };
            var widthBinding = new Binding("Width") { Source = viewModel, Mode = BindingMode.TwoWay };
            var xBinding = new Binding("X") { Source = viewModel, Mode = BindingMode.TwoWay };
            var yBinding = new Binding("Y") { Source = viewModel, Mode = BindingMode.TwoWay };

            ret.SetBinding(InkCanvas.LeftProperty, xBinding);
            ret.SetBinding(InkCanvas.TopProperty, yBinding);
            ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
            ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);

            return ret;
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:29,代码来源:EntityGridWidgetCreator.cs

示例6: AddContextMenu

        protected void AddContextMenu()
        {
            ContextMenu mainMenu = new ContextMenu();

            MenuItem item1 = new MenuItem() { Header = "Copy to Clipboard" };
            mainMenu.Items.Add(item1);

            MenuItem item1a = new MenuItem();
            item1a.Header = "96 dpi";
            item1.Items.Add(item1a);
            item1a.Click += OnClipboardCopy_96dpi;

            MenuItem item1b = new MenuItem();
            item1b.Header = "300 dpi";
            item1.Items.Add(item1b);
            item1b.Click += OnClipboardCopy_300dpi;

            MenuItem item1c = new MenuItem() { Header = "Enhanced Metafile" }; ;
            item1.Items.Add(item1c);
            item1c.Click += CopyToEMF;

            //MenuItem item2 = new MenuItem() { Header = "Print..." };
            //mainMenu.Items.Add(item2);
            //item2.Click += InvokePrint;
            windowsFormsHost.ContextMenu = mainMenu;
        }
开发者ID:goutkannan,项目名称:ironlab,代码行数:26,代码来源:MSChartHost.xaml.cs

示例7: MainWindow

        public MainWindow()
        {
            // ColorBrewer2 Set1
            defaultColors.Add(Color.FromRgb(228, 26, 28));
            defaultColors.Add(Color.FromRgb(55, 126, 184));
            defaultColors.Add(Color.FromRgb(77, 175, 74));
            defaultColors.Add(Color.FromRgb(152, 78, 163));
            defaultColors.Add(Color.FromRgb(255, 127, 0));
            defaultColors.Add(Color.FromRgb(255, 255, 51));
            defaultColors.Add(Color.FromRgb(166, 86, 40));
            defaultColors.Add(Color.FromRgb(247, 129, 191));
            defaultColors.Add(Color.FromRgb(153, 153, 153));

            LoadCellGroups();
            this.InitializeComponent();

            // Insert code required on object creation below this point.
            // Setting default color picker style
            colorMenu = (ContextMenu)(this.Resources["leftClickHSVMenu"]);
            // colorMenu = (ContextMenu)(this.Resources["leftClickRGBMenu"]);

            // Should be able to do this in the xaml...
            CollectionViewSource ldv = this.Resources["listingDataView"] as CollectionViewSource;
            if (ldv != null)
            {
                ldv.Source = CellConfigItems;
            }
        }
开发者ID:emonson,项目名称:WPFcolorPickerTest,代码行数:28,代码来源:MainWindow.xaml.cs

示例8: ExtendWithContextMenu

        public static void ExtendWithContextMenu(this TextEditor rtb)
        {
            ContextMenu ctx = new ContextMenu();

            MenuItem cut = new MenuItem();
            cut.Header = "Cut";
            cut.Click += (sender, e) => rtb.Cut();

            MenuItem copy = new MenuItem();
            copy.Header = "Copy";
            copy.Click += (sender, e) => rtb.Copy();

            MenuItem paste = new MenuItem();
            paste.Header = "Paste";
            paste.Click += (sender, e) => rtb.Paste();

            ctx.Items.Add(cut);
            ctx.Items.Add(copy);
            ctx.Items.Add(paste);

            rtb.ContextMenu = ctx;

            ctx.Opened +=
                (sender, e) =>
                {
                    bool noSelectedText = string.IsNullOrEmpty(rtb.SelectedText);

                    cut.IsEnabled = !noSelectedText;
                    copy.IsEnabled = !noSelectedText;

                    bool noClipboardText = string.IsNullOrEmpty(Clipboard.GetText());

                    paste.IsEnabled = !noClipboardText;
                };
        }
开发者ID:furesoft,项目名称:IntegratedJS,代码行数:35,代码来源:Extensions.cs

示例9: AudioCanvas

        public AudioCanvas()
        {
            /* The background must be set for the canvas mouse interaction to work properly,
             * otherwise the mouse events will fall through to the control "underneath" this one.
             */
            Background = Brushes.Transparent;

            _spaceImage = new Image();
            _waveformImage = new Image();

            //Add the two images in this over so that _space image is drawn over _waveformImage
            Children.Add(_waveformImage);
            Children.Add(_spaceImage);

            /* This method contains a null reference in the designer, causing an exception and not
             * rendering the canvas. This check guards against it.
             */
            if (!DesignerProperties.GetIsInDesignMode(this))
                SetBrushes();

            MouseSelection = CanvasMouseSelection.NoSelection;

            ContextMenu = new ContextMenu();

            InitEventHandlers();
        }
开发者ID:vserrago,项目名称:LiveDescribe-Desktop,代码行数:26,代码来源:AudioCanvas.cs

示例10: MainWindowContextMenuOpening

        private void MainWindowContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            var fe = sender as FrameworkElement;
            var _scriptingUIHelper = CompositionManager.Get<IScriptingUIHelper>();
            var _scriptingConfiguration = CompositionManager.Get<IScriptingConfiguration>();

            if (fe == null)
                return;

            var newcontextualmenu = new ContextMenu();
            if (_scriptingUIHelper != null)
            {
                List<object> menu = _scriptingUIHelper.CreateContextMenusFromScripts(false,
                                                                                     _scriptingConfiguration.
                                                                                         MainWindowContextMenuEntryPoint,
                                                                                     MenuItemClick);

                if (menu != null)
                {
                    foreach (object i in menu)
                        newcontextualmenu.Items.Add(i);
                }
            }

            fe.ContextMenu = newcontextualmenu;
        }
开发者ID:nickhodge,项目名称:MahTweets.LawrenceHargrave,代码行数:26,代码来源:StreamsContainer.xaml.cs

示例11: DesignerCanvas

		public DesignerCanvas(PlanDesignerViewModel planDesignerViewModel)
			: base(ServiceFactoryBase.Events)
		{
			GridLineController = new GridLineController(this);
			RemoveGridLinesCommand = new RelayCommand(OnRemoveGridLinesCommand);
			PlanDesignerViewModel = planDesignerViewModel;
			Toolbox = new ToolboxViewModel(this);
			ServiceFactoryBase.DragDropService.DragOver += OnDragServiceDragOver;
			ServiceFactoryBase.DragDropService.Drop += OnDragServiceDrop;
			PainterCache.Initialize(ServiceFactoryBase.ContentService.GetBitmapContent, ServiceFactoryBase.ContentService.GetDrawing);
			Width = 100;
			Height = 100;
			Focusable = false;
			DesignerSurface.AllowDrop = true;
			
			var menuItem = DesignerCanvasHelper.BuildMenuItem(
				"Вставить (Ctrl+V)", 
				"pack://application:,,,/Controls;component/Images/BPaste.png", 
				PlanDesignerViewModel.PasteCommand
			);
			menuItem.CommandParameter = this;
			var pasteItem = menuItem;

			ContextMenu = new ContextMenu();
			ContextMenu.HasDropShadow = false;
			ContextMenu.Items.Add(pasteItem);
			_moveAdorner = new MoveAdorner(this);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:28,代码来源:DesignerCanvas.cs

示例12: OptionsMenu

        public OptionsMenu()
        {
            InitializeComponent();

            ContextMenu = new ContextMenu();
            button.Click += (s, e) => ShowOptions();
        }
开发者ID:adymitruk,项目名称:storyteller,代码行数:7,代码来源:OptionsMenu.xaml.cs

示例13: AttachContextMenu

    private void AttachContextMenu(object sender, MouseButtonEventArgs e) {
      //this is PreviewMouseRightButtonDown on StackPanel in TreeView
      e.Handled = true;
      StackPanel stackPanel = (StackPanel) sender;
      object item = stackPanel.DataContext;

      if (stackPanel.ContextMenu != null) return;
      ContextMenu menu = new ContextMenu {Tag = item};

      switch (item.GetType().Name) {
        case nameof(ViewModel.Folders): {
          menu.Items.Add(new MenuItem {Command = (ICommand) Resources["FolderAdd"], CommandParameter = item});
          break;
        }
        case nameof(ViewModel.Folder): {
          if (((ViewModel.Folder) item).Parent == null) {
            menu.Items.Add(new MenuItem {Command = (ICommand) Resources["FolderRemove"], CommandParameter = item});
          }
          break;
        }
      }

      if (menu.Items.Count > 0)
        stackPanel.ContextMenu = menu;
    }
开发者ID:martin-holy,项目名称:PictureManager,代码行数:25,代码来源:DirectoryList.xaml.cs

示例14: AddMenuItem

 private static void AddMenuItem(ContextMenu menu, string text, string shortcut, EventHandler handler)
 {
     var item = new MenuItem();
     item.Header = text;
     item.Click += (s, e) => handler(s, e);
     menu.Items.Add(item);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:ZoomableInlineAdornment.cs

示例15: VideoCM

 private ContextMenu VideoCM()
 {
     var cm = new ContextMenu();
     cm.Items.Add(ContextMenuItems.Play(PlayVideo));
     cm.Items.Add(ContextMenuItems.Stop(StopVideo));
     return cm;
 }
开发者ID:undecimus,项目名称:komunikator,代码行数:7,代码来源:AddPlayVideoActionWindow.xaml.cs


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