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


C# ContextMenu.SetResourceReference方法代码示例

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


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

示例1: 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

示例2: 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)
        {
            CommandManager.InvalidateRequerySuggested();

            var menu = new ContextMenu();
            menu.SetResourceReference(ContextMenu.StyleProperty, Resources.ContextMenuStyleKey);

            // Generate view model
            var commands = new List<ICommandItem>();
            foreach (object tag in commandTags)
            {
                var command = m_commandService.GetCommand(tag);
                if (command != null)
                {
                    if (!AutoCompact || command.CanExecute(null))
                        commands.Add(command);
                }
                else
                {
                    // Allow direct display of ICommandItems which have not been registered
                    // with the command service
                    var commandItem = tag as ICommandItem;
                    if (commandItem != null && (!AutoCompact || commandItem.CanExecute(null)))
                        commands.Add(commandItem);
                }
            }
            commands.Sort(new CommandComparer());

            var dummyRootMenu = new RootMenuModel(null, null, null);
            foreach (ICommandItem command in commands)
                dummyRootMenu.AddItem(command);

            menu.ItemsSource = dummyRootMenu.Children;

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


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