本文整理汇总了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;
}
示例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;
}