本文整理汇总了C#中System.Windows.Controls.ContextMenu.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.Add方法的具体用法?C# ContextMenu.Add怎么用?C# ContextMenu.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.Add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _onContextMenuOpening
private void _onContextMenuOpening(object sender, ContextMenuEventArgs e) {
var item = _getTreeViewItem(e.OriginalSource);
if (item == null || !item.Header.IsA<ClassNode>()) {
e.Handled = true;
return;
}
var C = ((ClassNode)item.Header).Class;
var A = Shell.LoadedClasses;
var F = Shell.SelectedClasses;
var SUB = Shell.CurrentClass.SubClassesAndSelf;
Func<BplClass, bool> isSelected = c => (c != null && F.Contains(c));
var menu = new ContextMenu();
Action<string, Action, bool> addItem = (header, action, isEnabled) => {
var menuitem = new MenuItem() { Header = header, IsEnabled = isEnabled };
menuitem.Click += (sender2, e2) => action();
menu.Add(menuitem);
};
addItem("Select All", () => Shell.SelectAdditive(A), F.Count < A.Count);
addItem("Select Branch", () => Shell.SelectAdditive(SUB), SUB.Any(c => !isSelected(c)));
menu.Add();
addItem("Clear All", () => Shell.ClearAdditive(F), F.Count > 0);
addItem("Clear Branch", () => Shell.ClearAdditive(SUB), SUB.Any(c => isSelected(c)));
addItem("Clear Other Branches", () => Shell.ClearAdditive(F.Except(SUB)), C != null && C.BaseClass != null && F.Except(SUB).Any());
Selector.ContextMenu = menu;
}
示例2: _onOptionsMenuOpen
private void _onOptionsMenuOpen(object sender, RoutedEventArgs e) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = OptionsMenu;
var options = _getOutputOptions();
Action<string, BplDocumentationOptions> addToggle = (header, flag) => {
var menuitem = new MenuItem() { Header = header, Tag = flag, IsChecked = (options & flag) != 0};
menuitem.Click += _onOptionsMenuClick;
menu.Add(menuitem);
};
addToggle("Sort members by name", BplDocumentationOptions.SortMembers);
addToggle("Show inherited members", BplDocumentationOptions.ShowInherited);
addToggle("Show binary layout", BplDocumentationOptions.ShowBinaryLayout);
var syncitem = new MenuItem { Header = "Sync with table of contents", Tag = "Toc_SyncWithView", IsChecked = USER.Default.Toc_SyncWithView };
syncitem.Click += _onOptionsMenuClick;
menu.Add(syncitem);
OptionsMenu.ContextMenu = menu;
OptionsMenu.ContextMenu.IsOpen = true;
}
示例3: _defineContextMenu
private void _defineContextMenu() {
var menu = new ContextMenu();
Action<string, Action, bool> addItem = (header, action, isEnabled) => {
var menuitem = new MenuItem() { Header = header, IsEnabled = isEnabled };
menuitem.Click += (sender2, e2) => action();
menu.Add(menuitem);
};
if (Shell.CurrentClass != null) {
var node = DiagramCanvas.Nodes[Shell.CurrentClass];
addItem("Hide Class", () => Shell.ClearAdditive(node.Class), true);
addItem("Hide Other Classes", () => Shell.ClearAdditive(Shell.SelectedClasses.Where(c => c != node.Class)), true);
menu.Add();
addItem("Explore Related Classes", () => node.OpenRelatedClassesPopup(), true);
menu.Add();
}
addItem("View Documentation", () => {
Shell.ViewersContainer.SelectedIndex = 1;
}, true);
addItem("Generate Schema", () => {
Shell.SchemaViewer.ScopeSelector.SelectedIndex = (int)SchemaViewerScope.Current;
Shell.ViewersContainer.SelectedIndex = 2;
}, true);
addItem("Examine Protocol", () => {
Shell.ViewersContainer.SelectedIndex = 3;
}, true);
ContextMenu = menu;
}
示例4: OnMouseRightButtonDown
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
{
var cm = new ContextMenu();
TextBlock.SetTextAlignment(cm, TextAlignment.Left);
cm.Add(new MenuItem
{
IsEnabled = false,
Header = "Select dependency head",
Background = Brushes.Silver,
Foreground = Brushes.White,
});
cm.Add<MenuItem>(new MenuItem
{
Header = "(none)",
IsChecked = Part.Head == null,
}).Click += (o, ee) =>
{
Part.Head = null;
//var ic = tui.EnumerateVisualChildren().FirstOfType<ItemsControl>();
//var fe_head = (FrameworkElement)ic.ItemContainerGenerator.ContainerFromItem(dp_head);
//var fe_dep = (FrameworkElement)ic.ItemContainerGenerator.ContainerFromItem(dp_dep);
fe.ClearValue(TreeLayoutPanel.TreeParentProperty);
};
foreach (var dp_head in Part.AvailableHeads)
{
cm.Add<MenuItem>(new MenuItem
{
Header = dp_head.Text,
IsChecked = Part.Head == dp_head,
}).Click += (o, ee) =>
{
Part.Head = dp_head;
var fe_head = (FrameworkElement)ic.ItemContainerGenerator.ContainerFromItem(dp_head);
fe.SetValue(TreeLayoutPanel.TreeParentProperty, fe_head);
tlp.InvalidateVisual();
};
}
if (Part.Head != null)
{
cm.Add(new Separator());
var xx = (MenuItem)this.Resources["dep_types_menu"];
if (xx.Parent != null)
((ItemsControl)xx.Parent).Items.Remove(xx);
cm.Add(xx);
}
//cm.Add(new MenuItem
//{
// IsEnabled = false,
// Header = "Select dependency type",
// Background = Brushes.Silver,
// Foreground = Brushes.White,
//});
this.ContextMenu = cm;
base.OnMouseRightButtonDown(e);
}
示例5: _onLayoutMenuOpen
private void _onLayoutMenuOpen(object sender, RoutedEventArgs e) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = LayoutMenu;
Action<string, object, bool, bool> addToggle = (header, tag, isChecked, isEnabled) => {
var menuitem = new MenuItem() { Header = header, Tag = tag, IsChecked = isChecked, IsEnabled = isEnabled };
menuitem.Click += new RoutedEventHandler(_onLayoutMenuClick);
menu.Add(menuitem);
};
var layout = DiagramCanvas.LayoutMethod;
addToggle("Hierarchic layout", 11, layout == LayoutMethod.Hierarchic, true);
addToggle("Symmetric layout", 12, layout == LayoutMethod.Symmetric, true);
addToggle("Radial layout", 13, layout == LayoutMethod.Radial, true);
addToggle("Spring layout", 14, layout == LayoutMethod.Spring, true);
menu.Add(null);
if (DiagramCanvas.LayoutRatio == LayoutRatio.Fill) {
addToggle("Compress drawing", 21, false, true);
} else {
addToggle("Expand drawing", 22, false, true);
}
addToggle("Rotate drawing", 23, false, layout == LayoutMethod.Hierarchic);
addToggle("Flip drawing", 24, false, layout == LayoutMethod.Hierarchic);
LayoutMenu.ContextMenu = menu;
LayoutMenu.ContextMenu.IsOpen = true;
}
示例6: _onRoutingMenuOpen
private void _onRoutingMenuOpen(object sender, RoutedEventArgs e) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = RoutingMenu;
Action<string, DisplayOptions, bool> addToggle = (header, option, isEnabled) => {
var menuitem = new MenuItem() { Header = header, Tag = option, IsChecked = DiagramCanvas.DisplayOptions.Has(option), IsEnabled = isEnabled };
menuitem.Click += new RoutedEventHandler(_onRoutingMenuClick);
menu.Add(menuitem);
};
var layout = DiagramCanvas.LayoutMethod;
addToggle("Inheritance", DisplayOptions.ShowInheritance, true);
addToggle("Containment", DisplayOptions.ShowContainment, true);
addToggle("Associations", DisplayOptions.ShowAssociations, true);
addToggle("Collaborations", DisplayOptions.ShowCollaborations, true);
RoutingMenu.ContextMenu = menu;
RoutingMenu.ContextMenu.IsOpen = true;
}
示例7: _onDisplayMenuOpen
private void _onDisplayMenuOpen(object sender, RoutedEventArgs e) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = DisplayMenu;
Action<string, object, bool, bool> addToggle = (header, tag, isChecked, isEnabled) => {
var menuitem = new MenuItem() { Header = header, Tag = tag, IsChecked = isChecked, IsEnabled = isEnabled };
menuitem.Click += new RoutedEventHandler(_onDisplayMenuClick);
menu.Add(menuitem);
};
var option = DiagramCanvas.DisplayOptions;
var layout = DiagramCanvas.LayoutMethod;
var f1 = option.Has(DisplayOptions.DisplayClassNamespace);
var f2 = option.Has(DisplayOptions.GroupByNamespace);
var f3 = option.Has(DisplayOptions.DisplayClassMembers);
var f4 = option.Has(DisplayOptions.DisplayInheritedMembers);
var f5 = option.Has(DisplayOptions.SortMembersByName);
var f6 = option.Has(DisplayOptions.HideDisconnected);
addToggle("Show class namespace", DisplayOptions.DisplayClassNamespace, f1, true);
addToggle("Group by namespaces", DisplayOptions.GroupByNamespace, f2, (layout == LayoutMethod.Hierarchic || layout == LayoutMethod.Spring));
menu.Add(null);
addToggle("Show class members", DisplayOptions.DisplayClassMembers, f3, true);
addToggle("Show inherited members", DisplayOptions.DisplayInheritedMembers, f3 && f4, f3);
addToggle("Sort members by name", DisplayOptions.SortMembersByName, f5, f3);
menu.Add(null);
addToggle("Hide disconnected nodes", DisplayOptions.HideDisconnected, f6, true);
DisplayMenu.ContextMenu = menu;
DisplayMenu.ContextMenu.IsOpen = true;
}
示例8: OnContextMenuOpening
protected override void OnContextMenuOpening(ContextMenuEventArgs e) {
base.OnContextMenuOpening(e);
ContextMenu = new ContextMenu();
_addToggleMenu("Major gridlines", MajorGridlinesProperty);
_addTickmarkMenu("Major tick marks", MajorTickMarksProperty);
ContextMenu.Add();
_addToggleMenu("Minor gridlines", MinorGridlinesProperty);
_addTickmarkMenu("Minor tick marks", MinorTickMarksProperty);
ContextMenu.Add();
_addToggleMenu("Origin", ShowOriginProperty);
}
示例9: _buildFilterMenu
private void _buildFilterMenu() {
var topmenu = new ContextMenu {
Placement = PlacementMode.Bottom,
PlacementTarget = FilterMenu
};
Func<ItemsControl, string, string, MenuItem> addToggle = (menu, header, tag) => {
var menuitem = new MenuItem() { Header = header, Tag = tag };
menuitem.PreviewMouseLeftButtonDown += _onFilterMenuClick;
menuitem.PreviewMouseLeftButtonUp += (s, e2) => e2.Handled = true;
menu.Items.Add(menuitem);
return menuitem;
};
Func<Panel, string, string, CheckBox> addOption = (panel, header, tag) => {
var checkbox = new CheckBox() { Content = header, Tag = tag };
checkbox.PreviewMouseLeftButtonDown += _onFilterOptionClick;
checkbox.PreviewMouseLeftButtonUp += (s, e2) => e2.Handled = true;
panel.Children.Add(checkbox);
return checkbox;
};
Action<string> addSubMenu = key => {
var role = BplRole.Get(key);
var submenu = addToggle(topmenu, role.Description, role.Id.ToString(false));
foreach (var subrole in role.SubRoles) {
addToggle(submenu, subrole.Description, subrole.Id.ToString(false));
}
};
addToggle(topmenu, "All Roles", "All");
foreach (var role in _getTopLevelRoles()) {
addSubMenu(role.Id.ToString(false));
}
topmenu.Add(null);
var sp = new StackPanel { };
addOption(sp, "Consumer View", "Toc_ConsumerView");
addOption(sp, "Provider View", "Toc_ProviderView");
addOption(sp, "Related Classes", "Toc_RelatedClasses");
topmenu.Add(sp);
FilterMenu.ContextMenu = topmenu;
FilterMenu.IsEnabled = true;
_updateFilterMenu();
}
示例10: _onFormatMenuOpen
private void _onFormatMenuOpen(TextBox textBox, Button menuButton, DependencyProperty formatProperty, RoutedEventHandler handler) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = menuButton;
Action<BplFormat> addToggle = (format) => {
var menuitem = new MenuItem() {
Header = _toFormatName(format),
Tag = format,
IsChecked = (BplFormat)GetValue(formatProperty) == format,
Focusable = false
};
menuitem.Click += handler;
menu.Add(menuitem);
};
addToggle(BplFormat.Xml);
addToggle(BplFormat.Json);
addToggle(BplFormat.Json_t);
addToggle(BplFormat.Binary);
menu.Add(null);
var wrapItem = new MenuItem() {
Header = "Wrap text",
IsChecked = textBox.TextWrapping == TextWrapping.Wrap,
Focusable = false
};
wrapItem.Click += (s, e) => textBox.TextWrapping = (textBox.TextWrapping == TextWrapping.Wrap ? TextWrapping.NoWrap : TextWrapping.Wrap);
menu.Add(wrapItem);
menuButton.ContextMenu = menu;
menuButton.ContextMenu.IsOpen = true;
}
示例11: _onContextMenuOpening
private void _onContextMenuOpening(object sender, ContextMenuEventArgs e) {
var item = _getTreeViewItem(e.OriginalSource);
if (item == null || item.Header == null) {
e.Handled = true;
return;
}
var C = new HashSet<BplClass>();
var A = Shell.LoadedClasses;
var F = Shell.SelectedClasses;
Func<BplClass, bool> isSelected = c => (c != null && F.Contains(c));
if (item.Header.IsA<ClassNode>()) {
C.Add(((ClassNode)item.Header).Class);
} else if (item.Header.IsA<NamespaceNode>()) {
C.AddRange(((NamespaceNode)item.Header).Classes);
} else if (item.Header.IsA<LibraryNode>()) {
C.AddRange(((LibraryNode)item.Header).Children.SelectMany(g => g.Classes));
}
var menu = new ContextMenu();
Action<string, Action, bool> addItem = (header, action, isEnabled) => {
var menuitem = new MenuItem() { Header = header, IsEnabled = isEnabled };
menuitem.Click += (sender2, e2) => action();
menu.Add(menuitem);
};
addItem("Select All", () => Shell.SelectAdditive(A), F.Count < A.Count);
addItem("Clear All", () => Shell.ClearAdditive(F), F.Count > 0);
menu.Add();
addItem("Select Branch", () => Shell.SelectAdditive(C), C.Any(c => !isSelected(c)));
addItem("Clear Branch", () => Shell.ClearAdditive(C), C.Any(c => isSelected(c)));
addItem("Clear Other Branches", () => Shell.ClearAdditive(F.Except(C)), F.Except(C).Any());
Selector.ContextMenu = menu;
}