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


C# MenuItem.SetResourceReference方法代码示例

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


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

示例1: ToMenuItem

 public static MenuItem ToMenuItem(this IMenuRegister menuRegister, IShell shell)
 {
     var menuItem = new MenuItem
     {
         Header = menuRegister.Name,
         FontWeight = menuRegister.FontWeight,
         Tag = new MenuTag(menuRegister.Name, menuRegister.Group),
         Command = menuRegister.Command,
         CommandParameter = menuRegister.CommandParameter,
         IsCheckable = menuRegister.Checkable,
         Icon = menuRegister.Icon,
         FlowDirection = menuRegister.FlowDirection
     };
     if (menuRegister.Gesture != null)
     {
         menuItem.InputGestureText = menuRegister.Gesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture);
         shell.AddKeyBinding(menuItem.Command, menuRegister.Gesture);
     }
     INotifyPropertyChanged viewModel = null;
     if (menuRegister.ViewModelFactory != null)
     {
         viewModel = menuRegister.ViewModelFactory();
     }
     if (menuRegister.ViewFactory != null)
     {
         var view = menuRegister.ViewFactory(viewModel);
         view.DataContext = viewModel;
         menuItem.Header = view;
     }
     if (menuRegister.Style != null)
         menuItem.SetResourceReference(FrameworkElement.StyleProperty, menuRegister.Style);
     return menuItem;
 }
开发者ID:a-wall,项目名称:radar,代码行数:33,代码来源:MenuItemExtensions.cs

示例2: TextBoxBaseContextMenuOpening

        private static void TextBoxBaseContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            var tbBase = (TextBoxBase)sender;
            var textBox = tbBase as TextBox;
            var richTextBox = tbBase as RichTextBox;

            tbBase.ContextMenu = GetDefaultTextBoxBaseContextMenu();

            var cmdIndex = 0;
            var spellingError = textBox != null
                ? textBox.GetSpellingError(textBox.CaretIndex)
                : (richTextBox != null
                    ? richTextBox.GetSpellingError(richTextBox.CaretPosition)
                    : null);
            if (spellingError != null) {
                var suggestions = spellingError.Suggestions;
                if (suggestions.Any()) {
                    foreach (var suggestion in suggestions) {
                        var mi = new MenuItem();
                        mi.Header = suggestion;
                        mi.FontWeight = FontWeights.Bold;
                        mi.Command = EditingCommands.CorrectSpellingError;
                        mi.CommandParameter = suggestion;
                        mi.CommandTarget = tbBase;
                        mi.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
                        tbBase.ContextMenu.Items.Insert(cmdIndex, mi);
                        cmdIndex++;
                    }
                    // add a separator
                    tbBase.ContextMenu.Items.Insert(cmdIndex, new Separator());
                    cmdIndex++;
                }
                var ignoreAllMI = new MenuItem();
                ignoreAllMI.Header = "Ignore All";
                ignoreAllMI.Command = EditingCommands.IgnoreSpellingError;
                ignoreAllMI.CommandTarget = tbBase;
                ignoreAllMI.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
                tbBase.ContextMenu.Items.Insert(cmdIndex, ignoreAllMI);
                cmdIndex++;
                // add another separator
                var separatorMenuItem2 = new Separator();
                tbBase.ContextMenu.Items.Insert(cmdIndex, separatorMenuItem2);
            }
        }
开发者ID:rawbenny,项目名称:MahApps.Metro,代码行数:44,代码来源:TextboxHelper.cs

示例3: GetDefaultTextBoxBaseContextMenu

        // Gets a fresh context menu. 
        private static ContextMenu GetDefaultTextBoxBaseContextMenu()
        {
            var defaultMenu = new ContextMenu();

            var m1 = new MenuItem { Command = ApplicationCommands.Cut };
            m1.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
            var m2 = new MenuItem { Command = ApplicationCommands.Copy };
            m2.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
            var m3 = new MenuItem { Command = ApplicationCommands.Paste };
            m3.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");

            defaultMenu.Items.Add(m1);
            defaultMenu.Items.Add(m2);
            defaultMenu.Items.Add(m3);

            return defaultMenu;
        }
开发者ID:rawbenny,项目名称:MahApps.Metro,代码行数:18,代码来源:TextboxHelper.cs

示例4: CreateGroupHeader

 private MenuItem CreateGroupHeader()
 {
     var header = new MenuItem {Header = group.Name};
     header.SetResourceReference(StyleProperty, "MenuHeader");
     header.Background = @group.Controller != null
                             ? @group.Controller.TransparentBrush
                             : new SolidColorBrush(Color.FromArgb(100, 100, 100, 100));
     return header;
 }
开发者ID:jonbonne,项目名称:OCTGN,代码行数:9,代码来源:GroupControl.cs

示例5: CreateCardMenuItems

        protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
        {
            var items = new List<Control>();
            if (!card.CanManipulate())
            {
                var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush };
                item.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(item);

                item = new MenuItem { Header = "Take control" };
                item.Click += delegate { card.TakeControl(); };
                items.Add(item);
                return items;
            }
            else {
                var selection = Selection.ExtendToSelection(card);
                //actionFilter showCard = async (IGroupAction a) =>
                actionFilter showCard = (IGroupAction a) =>
                {
                    if (a.ShowIf != null)
                    {
                      //return await CallActionShowIf(a.ShowIf, selection);
                      return CallActionShowIf(a.ShowIf, selection);
                    }
                    return true;
                };
                var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList();
                //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask));
                //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray();
                var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray();
                var nCardActions = visibleActions.Length;

                if (nCardActions > 0 || group.Controller == null)
                {
                    var cardHeader = new MenuItem();
                    cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                    cardHeader.Header = card.Name;
                    cardHeader.Background = card.Controller.TransparentBrush;
                    items.Add(cardHeader);
                }
                if (nCardActions > 0)
                {
                    items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked)));
                    if (group.Controller == null)
                        items.Add(new Separator());
                }
                if (group.Controller == null)
                    items.Add(CreateCardPassToItem());
            }
            if (!card.FaceUp)
            {
              var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
              peekItem.Click += delegate { ContextCard.Peek(); };
              items.Add(peekItem);
            }

            return items;
        }
开发者ID:jonbonne,项目名称:OCTGN,代码行数:58,代码来源:GroupControl.cs

示例6: CreateCardMenuItems

        protected virtual List<Control> CreateCardMenuItems(DataNew.Entities.Group def)
        {
            var tempActions = def.CardActions.ToArray();
            int nCardActions = def.CardActions == null ? 0 : tempActions.Length;
            var items = new List<Control>();

            if (nCardActions > 0 || group.Controller == null)
            {
                _cardHeader = new MenuItem();
                _cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(_cardHeader);
            }
            if (nCardActions > 0)
            {
                for (int i = 0; i < nCardActions; i++)
                    items.Add(CreateCardMenuItem(tempActions[i]));
                if (group.Controller == null)
                    items.Add(new Separator());
            }
            if (group.Controller == null)
                items.Add(CreateCardPassToItem());

            return items;
        }
开发者ID:karlnp,项目名称:OCTGN,代码行数:24,代码来源:GroupControl.cs

示例7: ShowContextMenu

        internal virtual void ShowContextMenu(Card card, bool showGroupActions = true)
        {
            // Modify selection
            if (card == null || !card.Selected) Selection.Clear();

            var menuItems = new CompositeCollection();            
            ContextGroup = group;
            ContextMenu = new ContextMenu {ItemsSource = menuItems, Tag = card};
            // card has to captured somehow, otherwise it may be overwritten before released in the OnClosed handler, e.g. when rightclicking on a card, then directly right-clicking on another card.
            ContextMenu.Opened += (sender, args) =>
                                      {
                                          ContextGroup.KeepControl();
                                          var c = ((ContextMenu) sender).Tag as Card;
                                          if (c != null) c.KeepControl();
                                      };
            ContextMenu.Closed += (sender, args) =>
                                      {
                                          ContextGroup.ReleaseControl();
                                          var c = ((ContextMenu) sender).Tag as Card;
                                          if (c != null) c.ReleaseControl();
                                      };

            ContextCard = card;
            menuItems.Clear();

            if (group.CanManipulate())
            {
                if (card != null)
                {
                    if (card.CanManipulate())
                    {
                        if (_cardHeader != null)
                        {
                            _cardHeader.Header = card.Name;
                            _cardHeader.Background = card.Controller.TransparentBrush;
                            menuItems.Add(_cardMenu);
                        }
                    }
                    else
                    {
                        var item = new MenuItem {Header = card.Name, Background = card.Controller.TransparentBrush};
                        item.SetResourceReference(StyleProperty, "MenuHeader");
                        menuItems.Add(item);

                        item = new MenuItem {Header = "Take control"};
                        item.Click += delegate { card.TakeControl(); };
                        menuItems.Add(item);
                    }

                    if (!card.FaceUp)
                    {
                        var peekItem = new MenuItem {Header = "Peek", InputGestureText = "Ctrl+P"};
                        peekItem.Click += delegate { ContextCard.Peek(); };
                        if (menuItems.Count == 0)
                        {
                            var item = new MenuItem {Header = card.Name, Background = card.Owner.TransparentBrush};
                            item.SetResourceReference(StyleProperty, "MenuHeader");
                            menuItems.Add(item);
                        }
                        menuItems.Add(peekItem);
                    }
                }

                if (showGroupActions)
                    menuItems.Add(_groupMenu);
            }
            else// if (!group.WantToShuffle)
            {
                menuItems.Add(CreateGroupHeader());

                var item = new MenuItem {Header = "Take control"};
                item.Click += delegate { group.TakeControl(); };
                menuItems.Add(item);

                menuItems.Add(new Separator());
                item = CreateLookAtCardsMenuItem();
                if (item != null) menuItems.Add(item);
            }
            //else // Group is being shuffled
            //    return;

            ContextMenu.IsOpen = false;
            // Required to trigger the ReleaseControl calls if the ContextMenu was already open
            ContextMenu.UpdateLayout(); // Required if the ContextMenu was already open
            ContextMenu.IsOpen = true;
            ContextMenu.FontFamily = groupFont;
            ContextMenu.FontSize = fontsize;
        }
开发者ID:karlnp,项目名称:OCTGN,代码行数:88,代码来源:GroupControl.cs

示例8: CreateCardMenuItems

        protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
        {
            var items = new List<Control>();
            if (!card.CanManipulate())
            {
                var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush };
                item.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(item);

                item = new MenuItem { Header = "Take control" };
                item.Click += delegate { card.TakeControl(); };
                items.Add(item);
                return items;
            }
            else
            {
                var actions = def.CardActions.ToList();
                var nCardActions = actions.ToArray().Length;

                if (nCardActions > 0 || group.Controller == null)
                {
                    var cardHeader = new MenuItem();
                    cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                    cardHeader.Header = card.Name;
                    cardHeader.Background = card.Controller.TransparentBrush;
                    items.Add(cardHeader);
                }
                if (nCardActions > 0)
                {
                    items.AddRange(actions.Select(action => CreateActionMenuItem(action, CardActionClicked, card)).Where(x => x.Visibility == Visibility.Visible));
                    if (group.Controller == null)
                        items.Add(new Separator());
                }
                if (group.Controller == null)
                    items.Add(CreateCardPassToItem());
            }
            if (def.Id == Program.GameEngine.Definition.Table.Id)
            {
                var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" };
                ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false);
                items.Add(ami);
            }
            if (!card.FaceUp)
            {
                var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
                peekItem.Click += delegate { ContextCard.Peek(); };
                items.Add(peekItem);
            }
            return items;
        }
开发者ID:Bullgator351,项目名称:OCTGN,代码行数:50,代码来源:GroupControl.cs

示例9: CreateGroupHeader

 private MenuItem CreateGroupHeader()
 {
   MenuItem header = new MenuItem() { Header = group.Name };
   header.SetResourceReference(Control.StyleProperty, "MenuHeader");
   if (group.Controller != null)
     header.Background = group.Controller.TransparentBrush;
   else
     header.Background = new SolidColorBrush(Color.FromArgb(100, 100, 100, 100));
   return header;
 }
开发者ID:YoshiEnVerde,项目名称:OCTGN,代码行数:10,代码来源:GroupControl.cs

示例10: CreateCardMenuItems

    protected virtual List<Control> CreateCardMenuItems(GroupDef def)
    {
      int nCardActions = def.cardActions == null ? 0 : def.cardActions.Length;
      var items = new List<Control>();

      if (nCardActions > 0 || group.Controller == null)
      {
        cardHeader = new MenuItem();
        cardHeader.SetResourceReference(Control.StyleProperty, "MenuHeader");
        items.Add(cardHeader);
      }
      if (nCardActions > 0)
      {
        for (int i = 0; i < nCardActions; i++)
          items.Add(CreateCardMenuItem(def.cardActions[i]));
        if (group.Controller == null)
          items.Add(new Separator());
      }
      if (group.Controller == null)
        items.Add(CreateCardPassToItem());

      return items;
    }
开发者ID:YoshiEnVerde,项目名称:OCTGN,代码行数:23,代码来源:GroupControl.cs

示例11: BindMenu

        public void BindMenu()
        {
            List<NameValueInfo> listValues = new List<NameValueInfo>();
            listValues.Clear();
            List<NameValueInfo> listValues1 = new List<NameValueInfo>();
            listValues1.Clear();
                NameValueInfo valueinfo1 = new NameValueInfo();
                valueinfo1.nValue = 1;
                valueinfo1.sName = "旋转(左)";
                valueinfo1.sValue = "1";
                listValues.Add(valueinfo1);
                NameValueInfo valueinfo2 = new NameValueInfo();
                valueinfo2.nValue = 2;
                valueinfo2.sName = "旋转(右)";
                valueinfo2.sValue = "2";
                listValues.Add(valueinfo2);

                NameValueInfo valueinfo3 = new NameValueInfo();
                valueinfo3.nValue = 3;
                valueinfo3.sName = "前屈";
                valueinfo3.sValue = "3";
                listValues.Add(valueinfo3);
                NameValueInfo valueinfo4 = new NameValueInfo();
                valueinfo4.nValue = 4;
                valueinfo4.sName = "后伸";
                valueinfo4.sValue = "4";
                listValues.Add(valueinfo4);

                NameValueInfo valueinfo5 = new NameValueInfo();
                valueinfo5.nValue = 5;
                valueinfo5.sName = "旋转(左)";
                valueinfo5.sValue = "5";
                listValues1.Add(valueinfo5);
                NameValueInfo valueinfo6 = new NameValueInfo();
                valueinfo6.nValue = 6;
                valueinfo6.sName = "旋转(右)";
                valueinfo6.sValue = "6";
                listValues1.Add(valueinfo6);

                NameValueInfo valueinfo7 = new NameValueInfo();
                valueinfo7.nValue = 7;
                valueinfo7.sName = "前屈";
                valueinfo7.sValue = "7";
                listValues1.Add(valueinfo7);
                NameValueInfo valueinfo8 = new NameValueInfo();
                valueinfo8.nValue = 8;
                valueinfo8.sName = "后伸";
                valueinfo8.sValue = "8";
                listValues1.Add(valueinfo8);
            
            subMenu.Items.Clear();
            foreach (var item in listValues)
            {
                MenuItem mi = new MenuItem();
                if (item.sName.Length > 20)
                    mi.Header = item.sName.Substring(0, 10) + "...";
                else
                    mi.Header = item.sName;
                mi.Tag = item.sValue;
                mi.Click += new System.Windows.RoutedEventHandler(MenuClick);
                mi.SetResourceReference(MenuItem.StyleProperty, "MainMenuItem");
                subMenu.Items.Add(mi);
            }

            subMenu1.Items.Clear();
            foreach (var item in listValues1)
            {
                MenuItem mi = new MenuItem();
                if (item.sName.Length > 20)
                    mi.Header = item.sName.Substring(0, 10) + "...";
                else
                    mi.Header = item.sName;
                mi.Tag = item.sValue;
                mi.Click += new System.Windows.RoutedEventHandler(MenuClick);
                mi.SetResourceReference(MenuItem.StyleProperty, "MainMenuItem");
                subMenu1.Items.Add(mi);
            }
        }
开发者ID:wybq68,项目名称:DIH_LUMBARROBAT,代码行数:78,代码来源:MainWindow.xaml.cs

示例12: CreateCardMenuItems

 protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
 {
     var items = new List<Control>();
     var menuItem = new MenuItem { Header = card.Name, Background = card.Controller != null ? card.Controller.TransparentBrush : new SolidColorBrush(Color.FromArgb(100, 100, 100, 100)) };
     menuItem.SetResourceReference(StyleProperty, "MenuHeader");
     items.Add(menuItem);
     if (card.CanManipulate())
     {
         var selection = Selection.ExtendToSelection(card);
         //actionFilter showCard = async (IGroupAction a) =>
         actionFilter showCard = (IGroupAction a) =>
         {
             if (a.ShowIf != null)
             {
                 //return await CallActionShowIf(a.ShowIf, selection);
                 return CallActionShowIf(a.ShowIf, selection);
             }
             return true;
         };
         var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList();
         //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask));
         //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray();
         var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray();
         var nCardActions = visibleActions.Length;
         if (nCardActions > 0)
         {
             items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked)));
             if (group.Controller == null)
                 items.Add(new Separator());
         }
     }
     if (card.Controller != Player.LocalPlayer)
     {
         var item = new MenuItem { Header = "Take control" };
         item.Click += delegate { card.TakeControl(); };
         items.Add(item);
         return items;
     }
     else
     {
         if (group.Controller == null)
             items.Add(CreateCardPassToItem());
     }
     if (def.Id == Program.GameEngine.Definition.Table.Id)
     {
         var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" };
         ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false);
         items.Add(ami);
     }
     if (!card.FaceUp)
     {
         var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
         peekItem.Click += delegate { ContextCard.Peek(); };
         items.Add(peekItem);
     }
     return items;
 }
开发者ID:Keterr,项目名称:OCTGN,代码行数:57,代码来源:GroupControl.cs


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