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


C# MenuItem.SetBinding方法代码示例

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


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

示例1: AddTrayIconWpf

        private void AddTrayIconWpf() {
            Application.Current.Dispatcher.Invoke(() => {
                var rhm = new MenuItem { Header = "RHM Settings", Command = RhmService.Instance.ShowSettingsCommand };
                rhm.SetBinding(UIElement.VisibilityProperty, new Binding {
                    Source = RhmService.Instance,
                    Path = new PropertyPath(nameof(RhmService.Active))
                });

                var restore = new MenuItem { Header = UiStrings.Restore };
                var close = new MenuItem { Header = UiStrings.Close };

                restore.Click += RestoreMenuItem_Click;
                close.Click += CloseMenuItem_Click;

                _icon = new TaskbarIcon {
                    Icon = AppIconService.GetTrayIcon(),
                    ToolTipText = AppStrings.Hibernate_TrayText,
                    ContextMenu = new ContextMenu {
                        Items = {
                            rhm,
                            restore,
                            new Separator(),
                            close
                        }
                    },
                    DoubleClickCommand = new DelegateCommand(WakeUp)
                };

            });
        }
开发者ID:gro-ove,项目名称:actools,代码行数:30,代码来源:AppHibernator.TaskbarIcon.cs

示例2: Hyperlink_Click

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            var hyperlink = (Hyperlink) sender;
            var vm = (TaskAreaItemsViewModel) hyperlink.DataContext;

            var contextMenu = new ContextMenu {PlacementTarget = (UIElement) hyperlink.Parent, Placement = PlacementMode.Right, HorizontalOffset = 14, DataContext = vm,
                Style = (Style) FindResource("TaskAreaContextMenuStyle")};

            bool prevWasGroup = false;
            foreach (TaskAreaViewModelBase item in vm.Items)
            {
                var group = item as TaskAreaCommandGroupViewModel;
                if (group != null)
                {
                    if (contextMenu.Items.Count > 0)
                        contextMenu.Items.Add(new Separator {Style = (Style) FindResource("TaskAreaSeparatorStyle")});

                    foreach (TaskAreaCommandViewModel command in group.Commands)
                    {
                        var menuItem = new MenuItem {Header = command.DisplayName, Command = command.Command, DataContext = command, Tag = group, Style = (Style) FindResource("TaskAreaMenuItemStyle")};
                        menuItem.Click += menuItem_Click;
                        if (command == group.SelectedCommand)
                        {
                            var geometry = new EllipseGeometry(new Point(0, 0), 3, 3);
                            var drawingBrush = new DrawingBrush(new GeometryDrawing {Brush = Brushes.Black, Geometry = geometry}) {Stretch = Stretch.None};
                            menuItem.Icon = new Image {Source = new DrawingImage(drawingBrush.Drawing)};
                        }
                        contextMenu.Items.Add(menuItem);
                    }
                    prevWasGroup = true;
                }
                else
                {
                    if (prevWasGroup)
                        contextMenu.Items.Add(new Separator {Style = (Style) FindResource("TaskAreaSeparatorStyle")});

                    prevWasGroup = false;
                    var command = item as TaskAreaCommandViewModel;
                    if (command != null)
                    {
                        var menuItem = new MenuItem {Header = command.DisplayName, Command = command.Command, DataContext = command, Style = (Style) FindResource("TaskAreaMenuItemStyle")};
                        contextMenu.Items.Add(menuItem);
                    }
                    else
                    {
                        var booleanItem = item as TaskAreaBooleanViewModel;
                        if (booleanItem != null)
                        {
                            var menuItem = new MenuItem {Header = booleanItem.DisplayName, DataContext = booleanItem, Style = (Style) FindResource("TaskAreaMenuItemStyle"), IsCheckable = true};
                            menuItem.SetBinding(MenuItem.IsCheckedProperty, "Value");
                            contextMenu.Items.Add(menuItem);
                        }
                    }
                }
            }
            contextMenu.IsOpen = true;
        }
开发者ID:rmunn,项目名称:cog,代码行数:57,代码来源:TaskAreaItemsView.xaml.cs

示例3: LedgerEntryControl

        public LedgerEntryControl()
        {
            InitializeComponent();

            ContextMenu contextMenu = new ContextMenu();
            MenuItem voidMenuItem = new MenuItem() { Header = "Void" };
            voidMenuItem.SetBinding(MenuItem.CommandProperty, new Binding("Void"));
            contextMenu.Items.Add(voidMenuItem);
            ContextMenuService.SetContextMenu(this, contextMenu);
        }
开发者ID:michaellperry,项目名称:Ledger,代码行数:10,代码来源:LedgerEntryControl.xaml.cs

示例4: AppendToContextMenu

 private static void AppendToContextMenu(ContextMenu menu, ISearchEngine engine)
 {
     var item = new MenuItem()
     {
         Header = "search on " + engine.Name,
         Tag = engine
     };
     item.Click += SearchStringOnEngine_OnClick;
     item.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("InfoView.SeriesView.Source.Names"));
     menu.Items.Add(item);
 }
开发者ID:gitter-badger,项目名称:JRYVideo,代码行数:11,代码来源:VideoViewerPage.xaml.cs

示例5: PointSelector

		public PointSelector()
		{
			markerChart.SetBinding(Panel.ZIndexProperty, new Binding("(Panel.ZIndex)") { Source = this });

			// initializing built-in commands
			removePointCommand = new LambdaCommand((param) => RemovePointExecute(param), RemovePointCanExecute);
			changeModeCommand = new LambdaCommand((param) => ChangeModeExecute(param), ChangeModeCanExecute);
			addPointCommand = new LambdaCommand((param) => AddPointExecute(param), AddPointCanExecute);

			InitializeComponent();

			// adding context menu binding to markers
			markerChart.AddPropertyBinding(DefaultContextMenu.PlotterContextMenuProperty, data =>
			{
				ObjectCollection menuItems = new ObjectCollection();

				MenuItem item = new MenuItem { Header = UIResources.PointSelector_RemovePoint, Command = PointSelectorCommands.RemovePoint, CommandTarget = this };
				item.SetBinding(MenuItem.CommandParameterProperty, new Binding());
				menuItems.Add(item);

				return menuItems;
			});

			// loading marker template
			var markerTemplate = (DataTemplate)Resources["markerTemplate"];
			markerChart.MarkerBuilder = new TemplateMarkerGenerator(markerTemplate);
			markerChart.ItemsSource = points;

			// adding bindings to commands from PointSelectorCommands static class
			CommandBinding removePointBinding = new CommandBinding(
				PointSelectorCommands.RemovePoint,
				RemovePointExecute,
				RemovePointCanExecute
				);
			CommandBindings.Add(removePointBinding);

			CommandBinding changeModeBinding = new CommandBinding(
				PointSelectorCommands.ChangeMode,
				ChangeModeExecute,
				ChangeModeCanExecute);
			CommandBindings.Add(changeModeBinding);

			CommandBinding addPointBinding = new CommandBinding(
				PointSelectorCommands.AddPoint,
				AddPointExecute,
				AddPointCanExecute);
			CommandBindings.Add(addPointBinding);

			// init add point menu item
			addPointMenuItem.Click += addPointMenuItem_Click;

			points.CollectionChanged += points_CollectionChanged;
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:53,代码来源:PointSelector.xaml.cs

示例6: BindMenuText

 private void BindMenuText(MenuItem menuItem, DependencyProperty property)
 {
     var binding = new Binding { Source = this, Path = new PropertyPath(property) };
     menuItem.SetBinding(HeaderedItemsControl.HeaderProperty, binding);
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:ExplorerViewMenu.cs

示例7: MenuItemFromNavigationPaneItem

        private MenuItem MenuItemFromNavigationPaneItem(NavigationPaneItem item, bool isHiddenItem)
        {
            MenuItem menuItem = new MenuItem();

               menuItem.IsCheckable = true;

               Binding b = new Binding();
               b.Source = item;
               if (isHiddenItem)
            b.Path = new PropertyPath(Selector.IsSelectedProperty);
               else
               {
            b.Path = new PropertyPath(NavigationPane.IsItemExcludedProperty);
            b.Converter = new BooleanNegateConverter();
               }
               b.Mode = BindingMode.TwoWay;

               menuItem.SetBinding(MenuItem.IsCheckedProperty, b);

               if (item.ImageSmall != null)
               {
            Image image = new Image();
            image.Width = 16;
            image.Height = 16;
            image.Source = item.ImageSmall;
            menuItem.Icon = image;
               }
               menuItem.Header = XamlHelper.CloneUsingXaml(item.Header, true);

               return menuItem;
        }
开发者ID:zhengjin,项目名称:WindowDemo,代码行数:31,代码来源:NavigationPaneConfigure.cs

示例8: OnContextMenuOpening

        protected void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            var uc = (UserControl)sender;
            var cm = uc.ContextMenu;
            var ws = (WeiboStatus)DataContext;
            if (cm.Items.Count != 0)//all are ready
            {
                return;
            }

            cm.Items.Add(new MenuItem()
            {
                Header = "复制到剪贴板",
                Command = WeiZhiCommands.CopyTweet,
                CommandParameter = ws
            });
            cm.Items.Add(new MenuItem()
            {
                Header = string.Format("复制 @{0} 到剪贴板", ws.user.screen_name),
                Command = WeiZhiCommands.CopyName,
                CommandParameter = ws.user.screen_name
            });
            if (ws.has_rt)
            {
                cm.Items.Add(new MenuItem
                {
                    Header = "复制原推内容到剪贴板",
                    Command = WeiZhiCommands.CopyTweet,
                    CommandParameter = ws.retweeted_status
                });
                cm.Items.Add(new MenuItem
                {
                    Header = string.Format("复制 @{0} 到剪贴板", ws.retweeted_status.user.screen_name),
                    Command = WeiZhiCommands.CopyName,
                    CommandParameter = ws.retweeted_status.user.screen_name
                });
            }

            cm.Items.Add(new Separator());
            //cm.Items.Add(new MenuItem
            //{
            //    Header = "在浏览器中查看此微博",
            //    Command = WeiZhiCommands.ViewWeiboViaWeb,
            //    CommandParameter = ws
            //});
            cm.Items.Add(new MenuItem { Header = string.Format("在浏览器中查看 @{0}", ws.user.screen_name), Command = WeiZhiCommands.ViewUserViaWeb, CommandParameter = ws.user });
            if (ws.has_rt)
                cm.Items.Add(new MenuItem { Header = string.Format("在浏览器中查看 @{0}", ws.retweeted_status.user.screen_name), Command = WeiZhiCommands.ViewUserViaWeb, CommandParameter = ws.retweeted_status.user });
            if (!ws.url.is_empty)
            {
                if (ws.url.has_document)
                    cm.Items.Add(new MenuItem { Header = string.Format("在浏览器中查看 {0}", ws.url.short_path) , Command = WeiZhiCommands.NavigateUrl, CommandParameter = ws.url.url_short });
                if (ws.url.has_media)
                    cm.Items.Add(new MenuItem { Header = string.Format("在浏览器中播放 {0}", ws.url.short_path), Command = WeiZhiCommands.NavigateUrl, CommandParameter = ws.url.url_short });
            }
            if (ws.has_pic)
                cm.Items.Add(new MenuItem { Header = "打开图片", Command = WeiZhiCommands.NavigateUrl, CommandParameter = ws.bmiddle_pic });

            cm.Items.Add(new Separator());
            var fc = new MenuItem()
            {
                Command = WeiZhiCommands.FollowUnfollow,
                CommandParameter = ws.user
            };
            var bd = new Binding("user.following") { Converter = new FollowCommandConverter(ws.user.screen_name), Mode = BindingMode.OneWay };
            fc.SetBinding(HeaderedItemsControl.HeaderProperty, bd);
            cm.Items.Add(fc);

            if (ws.has_rt && ws.user.id != ws.retweeted_status.user.id)
            {
                var ff = new MenuItem
                {
                    Command = WeiZhiCommands.FollowUnfollow,
                    CommandParameter = ws.retweeted_status.user
                };
                var rbd = new Binding("retweeted_status.user.following") { Converter = new FollowCommandConverter(ws.retweeted_status.user.screen_name),Mode=BindingMode.OneWay };
                ff.SetBinding(HeaderedItemsControl.HeaderProperty, rbd);
                cm.Items.Add(ff);
                
            }
            cm.Items.Add(new Separator());
            cm.Items.Add(new MenuItem { Header = "转发/评论", Command = ((WeiboStatus)DataContext).show_editor, CommandParameter = ws });
            cm.Items.Add(new MenuItem { Header = "直接转发", Command = WeiZhiCommands.RetweetDirectly, CommandParameter = ws });

            var l = (ViewModelLocator)FindResource("Locator");
            var cid = l.AccessToken.id();
            if (cid == ws.user.id)
                cm.Items.Add(new MenuItem { Header = "删除", Command = WeiZhiCommands.DestroyStatus, CommandParameter = ws });
            if (ws.has_rt)
            {
                cm.Items.Add(new MenuItem
                {
                    Header = string.Format("转发 @{0}的原微博", ws.retweeted_status.user.screen_name),
                    Command = WeiZhiCommands.Retweet,
                    CommandParameter = ws.retweeted_status
                });
                cm.Items.Add(new MenuItem
                {
                    Header = string.Format("评论 @{0}的原微博", ws.retweeted_status.user.screen_name),
                    Command = WeiZhiCommands.Reply,
//.........这里部分代码省略.........
开发者ID:heartszhang,项目名称:WeiZhi3,代码行数:101,代码来源:WeiboControlBase.cs

示例9: CloneContextMenuItem

        object CloneContextMenuItem(object obj)
        {
            if (obj is Separator)
            {
                return new Separator();
            }

            var item = obj as MenuItem;

            if (item == null)
            {
                return obj;
            }

            var clone = new MenuItem();

            foreach (var dp in clonedMenuItemProperties)
            {
                var binding = BindingOperations.GetBinding(item, dp);

                if (binding != null)
                {
                    clone.SetBinding(dp, binding);
                }
                else
                {
                    clone.SetValue(dp, item.GetValue(dp));
                }
            }

            if (item.Items.Count > 0)
            {
                foreach (var child in item.Items.OfType<object>())
                {
                    clone.Items.Add(CloneContextMenuItem(child));
                }
            }

            return clone;
        }
开发者ID:UnaNancyOwen,项目名称:Kinect-Studio-Sample,代码行数:40,代码来源:TreeGrid.cs

示例10: Tile_Click

 private void Tile_Click(object sender, RoutedEventArgs e)
 {
     Tile tile = (Tile)sender;
     WorkItem item = (WorkItem)tile.Tag;
     if (WindowList.ContainsKey(item))
     {
         WindowList[item].Close += frame_Close;
         ContentControl.Content = WindowList[item];
         return;
     }
     WorkFrame frame = new WorkFrame();
     frame.MainTitle = item.Name;
     WorkPage content = item.GetWorkPage();
     WindowList.Add(item, frame);
     MenuItem menu = new MenuItem();
     menu.Tag = frame;
     menu.Click += Menu_Click;
     menu.SetBinding(MenuItem.HeaderProperty, new Binding { Source = frame, Mode = BindingMode.OneWay, Path = new PropertyPath("Content.Title") });
     WindowMenu.Items.Add(menu);
     frame.Close += frame_Close;
     frame.Close += (s, ee) =>
         {
             WindowList.Remove(item);
             WindowMenu.Items.Remove(menu);
             ContentControl.Content = StartMenu;
         };
     ContentControl.Content = frame;
     frame.NavigationService.NavigateTo(content);
 }
开发者ID:liny4cn,项目名称:ComBoost,代码行数:29,代码来源:MainWindow.xaml.cs

示例11: CreateUserContextMenu

        private void CreateUserContextMenu()
        {
            UserContextMenu = new ContextMenu();
            var whisper = new MenuItem();
            whisper.Header = "Whisper";
            whisper.Click += WhisperOnClick;
            UserContextMenu.Items.Add(whisper);

            var addFriend = new MenuItem();
            addFriend.Header = "Add Friend";
            addFriend.Click += AddFriendOnClick;
            UserContextMenu.Items.Add(addFriend);

            var ban = new MenuItem();
            ban.Header = "Ban";
            ban.Click += BanOnClick;
            UserContextMenu.Items.Add(ban);

            var profile = new MenuItem();
            profile.Header = "Profile";
            profile.Click += ProfileOnClick;
            UserContextMenu.Items.Add(profile);

            var binding = new System.Windows.Data.Binding();
            binding.Mode = System.Windows.Data.BindingMode.OneWay;
            binding.Converter = new BooleanToVisibilityConverter();
            binding.Source = BanMenuVisible;

            ban.SetBinding(VisibilityProperty, binding);
        }
开发者ID:Cosworth32,项目名称:OCTGN,代码行数:30,代码来源:ChatControl.xaml.cs

示例12: ContextMenuGen

        /// <summary>
        /// コンテキストメニューを生成、バインドします。
        /// </summary>
        private void ContextMenuGen()
        {
            ContextMenu menu = new ContextMenu();
            // Check URL
            MenuItem menuItemCheckable = new MenuItem()
            {
                IsCheckable = true,
                Header = Properties.Resources.menuCheck
            };
            menuItemCheckable.SetBinding(MenuItem.IsCheckedProperty, new Binding("Check"));
            menu.Items.Add(menuItemCheckable);

            // Re-Auth
            MenuItem menuItemReAuth = new MenuItem();
            menuItemReAuth.Header = Properties.Resources.menuReauth;
            menuItemReAuth.Click += ReAuth;
            menu.Items.Add(menuItemReAuth);
            // About APP
            MenuItem menuItemAbout = new MenuItem();
            menuItemAbout.Header = string.Format(Properties.Resources.AboutThis, "TwVideoUp");
            menuItemAbout.Click += AboutApp;
            menu.Items.Add(menuItemAbout);

            ContextMenu = menu;
        }
开发者ID:hinaloe,项目名称:TwitterVideoUploader,代码行数:28,代码来源:MainWindow.xaml.cs

示例13: ShowNewQueryWindow

        private void ShowNewQueryWindow(string fileName,
            bool show,
            Dictionary<string, ParameterResolver> resolvers)
        {
            if (QueryWindows.Activate(fileName))
            {
                return;
            }

            QueryModel queryModel = new QueryModel(this.Model);
            QueryEditorModel editor = new QueryEditorModel();
            editor.ParameterResolvers = resolvers;
            editor.LoadFile(fileName);
            QueryEditorView view = new QueryEditorView(editor, queryModel);
            QueryWindows.Create(view, show);

            // Add to the menu collection.
            MenuItem newMenu = new MenuItem();
            newMenu.Click += (s, eargs) => QueryWindows.Activate(view);
            newMenu.DataContext = view;
            Binding b = new Binding("Title");
            b.Source = view;
            newMenu.SetBinding(MenuItem.HeaderProperty, b);
            int index = QueryWindows.Count();
            if (String.IsNullOrEmpty(fileName))
            {
                //  Add ":" to give create an invalid filename.
                view.Title = string.Format("{0}{1}New Query", index, QueryEditorView.TitleSeperator);
            }
            else
            {
                view.Title = string.Format("{0}{1}{2}", index, QueryEditorView.TitleSeperator, fileName);
            }

            this.QueriesMenu.Items.Add(newMenu);

            // Remove from the menu collection upon close.
            CancelEventHandler closeHandler = (sender, args) =>
            {
                QueryWindows.Activate(view);
                view.Close(args);
            };

            queryModel.OnDisposed += (s, e1) =>
            {
                this.QueriesMenu.Items.Remove(newMenu);
                QueryWindows.Remove(view);
                MainModel.CloseEventHandler -= closeHandler;
            };

            MainModel.CloseEventHandler += closeHandler;
        }
开发者ID:aelij,项目名称:svcperf,代码行数:52,代码来源:MainWindow.xaml.cs

示例14: SetMenutItemVisibilityBinding

 private void SetMenutItemVisibilityBinding(MenuItem menuItem)
 {
     //Binds the Visibility to the IsEnabled property for a given MenuItem
     //Essentially collapses items rather than gray them out when predicate is not matched
     var visibilityBinding = new Binding()
     {
         Source = menuItem,
         Path = new PropertyPath("IsEnabled"),
         Converter = new Utility.VisibilityConverter()
     };
     menuItem.SetBinding(MenuItem.VisibilityProperty, visibilityBinding);
 }
开发者ID:YHTechnology,项目名称:ProjectManager,代码行数:12,代码来源:CustomDocumentViewer.cs

示例15: CreateMenuItem

        private static MenuItem CreateMenuItem(string name, string automationId, RoutedCommand command)
        { 
            MenuItem menuItem = new MenuItem();
            menuItem.Header = SR.Get(name);
            menuItem.Command = command;
            AutomationProperties.SetAutomationId(menuItem, automationId); 

            Binding binding = new Binding(); 
            binding.Path = new PropertyPath(ContextMenu.PlacementTargetProperty); 
            binding.Mode = BindingMode.OneWay;
            binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ContextMenu), 1); 
            menuItem.SetBinding(MenuItem.CommandTargetProperty, binding);

            return menuItem;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:15,代码来源:ScrollBar.cs


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