本文整理汇总了C#中IMenuItem.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IMenuItem.GetType方法的具体用法?C# IMenuItem.GetType怎么用?C# IMenuItem.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMenuItem
的用法示例。
在下文中一共展示了IMenuItem.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
MenuItem Create(IMenuItem item, IMenuItemMetadata metadata, IMenuItemContext ctx, IInputElement commandTarget, MenuItem menuItem, bool isCtxMenu)
{
if (menuItem == null)
menuItem = new MenuItem();
menuItem.CommandTarget = commandTarget;
string header = ResourceHelper.GetString(item, metadata.Header);
string inputGestureText = ResourceHelper.GetString(item, metadata.InputGestureText);
string iconName = metadata.Icon;
var mi2 = item as IMenuItem2;
if (mi2 != null) {
header = mi2.GetHeader(ctx) ?? header;
inputGestureText = mi2.GetInputGestureText(ctx) ?? inputGestureText;
iconName = mi2.GetIcon(ctx) ?? iconName;
menuItem.IsChecked = mi2.IsChecked(ctx);
}
menuItem.Header = header;
menuItem.InputGestureText = inputGestureText;
var cmdHolder = item as ICommandHolder;
bool lastIsEnabledCallValue = false;
if (!string.IsNullOrEmpty(iconName)) {
if (cmdHolder == null)
lastIsEnabledCallValue = item.IsEnabled(ctx);
else {
var routedCommand = cmdHolder.Command as RoutedCommand;
lastIsEnabledCallValue = commandTarget == null || routedCommand == null || routedCommand.CanExecute(ctx, commandTarget);
}
imageManager.Add16x16Image(menuItem, item.GetType().Assembly, iconName, isCtxMenu, lastIsEnabledCallValue);
}
if (metadata.Guid != null) {
var itemGuid = Guid.Parse(metadata.Guid);
List<MenuItemGroupMD> list;
if (guidToGroups.TryGetValue(itemGuid, out list)) {
menuItem.Items.Add(new MenuItem());
menuItem.SubmenuOpened += (s, e) => {
if (e.Source == menuItem)
InitializeSubMenu(menuItem, ctx, itemGuid, commandTarget, isCtxMenu);
};
menuItem.SubmenuClosed += (s, e) => {
if (e.Source == menuItem) {
menuItem.Items.Clear();
menuItem.Items.Add(new MenuItem());
}
};
}
}
menuItem.Command = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => item.Execute(ctx), a => {
bool b = item.IsEnabled(ctx);
if (lastIsEnabledCallValue != b && !string.IsNullOrEmpty(iconName))
imageManager.Add16x16Image(menuItem, item.GetType().Assembly, iconName, isCtxMenu, lastIsEnabledCallValue = b);
return b;
});
return menuItem;
}
示例2: Usable
private bool Usable(IMenuItem item)
{
return new[] { typeof(MenuLabel) }.All(m => item.GetType() != m);
}
示例3: AddMenuItem
public void AddMenuItem(IMenuItem item, string path)
{
// Ensure item is a WPF Menu Item
if (item.GetType() != typeof(MenuItem)) {
throw new IncompatibleObjectException(item);
}
else menubar.AddItem(path, (MenuItem)item);
}