本文整理汇总了C#中System.Windows.Controls.ContextMenu类的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu类的具体用法?C# ContextMenu怎么用?C# ContextMenu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextMenu类属于System.Windows.Controls命名空间,在下文中一共展示了ContextMenu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWidgetControl
public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu)
{
var buttonHolder = widgetViewModel as EntityButtonWidgetViewModel;
var ret = new FlexButton.FlexButton { DataContext = buttonHolder, ContextMenu = contextMenu, CommandParameter = buttonHolder };
var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var captionBinding = new Binding("Settings.Caption") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var radiusBinding = new Binding("CornerRadius") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var buttonColorBinding = new Binding("ButtonColor") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var commandBinding = new Binding("ItemClickedCommand") { Source = buttonHolder, Mode = BindingMode.OneWay };
var enabledBinding = new Binding("IsEnabled") { Source = buttonHolder, Mode = BindingMode.OneWay };
var rotateTransform = new Binding("RotateTransform") { Source = buttonHolder, Mode = BindingMode.OneWay };
ret.SetBinding(InkCanvas.LeftProperty, xBinding);
ret.SetBinding(InkCanvas.TopProperty, yBinding);
ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);
ret.SetBinding(ContentControl.ContentProperty, captionBinding);
ret.SetBinding(FlexButton.FlexButton.CornerRadiusProperty, radiusBinding);
ret.SetBinding(FlexButton.FlexButton.ButtonColorProperty, buttonColorBinding);
ret.SetBinding(ButtonBase.CommandProperty, commandBinding);
ret.SetBinding(FrameworkElement.LayoutTransformProperty, rotateTransform);
//ret.SetBinding(UIElement.IsEnabledProperty, enabledBinding);
return ret;
}
示例2: CreateWidgetControl
public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu)
{
var buttonHolder = widgetViewModel as TicketExplorerViewModel;
var ret = new TicketExplorerView { DataContext = buttonHolder, ContextMenu = contextMenu };
var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var radiusBinding = new Binding("CornerRadius") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var buttonColorBinding = new Binding("ButtonColor") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var enabledBinding = new Binding("IsEnabled") { Source = buttonHolder, Mode = BindingMode.OneWay };
var transformBinding = new Binding("RenderTransform") { Source = buttonHolder, Mode = BindingMode.OneWay };
ret.SetBinding(InkCanvas.LeftProperty, xBinding);
ret.SetBinding(InkCanvas.TopProperty, yBinding);
ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);
//ret.SetBinding(FlexButton.FlexButton.CornerRadiusProperty, radiusBinding);
//ret.SetBinding(FlexButton.FlexButton.ButtonColorProperty, buttonColorBinding);
//ret.SetBinding(UIElement.RenderTransformProperty, transformBinding);
//ret.SetBinding(UIElement.IsEnabledProperty, enabledBinding);
return ret;
}
示例3: 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;
}
示例4: SetupContextMenu
private void SetupContextMenu()
{
var ctm = new ContextMenu {Background = Brushes.DarkGray};
var miSmall = new MenuItem();
miSmall.Click += ChangetoSmall;
miSmall.Header = "Small";
miSmall.Foreground = Brushes.White;
var miNormal = new MenuItem();
miNormal.Click += ChangetoNormal;
miNormal.Header = "Normal";
miNormal.Foreground = Brushes.White;
var miLarge = new MenuItem();
miLarge.Click += ChangetoLarge;
miLarge.Header = "Large";
miLarge.Foreground = Brushes.White;
var miChangeSize = new MenuItem
{
Header = "Change Size",
Foreground = Brushes.White
};
miChangeSize.Items.Add(miSmall);
miChangeSize.Items.Add(miNormal);
miChangeSize.Items.Add(miLarge);
ctm.Items.Add(miChangeSize);
ContextMenu = ctm;
}
示例5: CreateWidgetControl
public FrameworkElement CreateWidgetControl(IDiagram widget, ContextMenu contextMenu)
{
var viewModel = widget as EntityGridWidgetViewModel;
Debug.Assert(viewModel != null);
if (widget.DesignMode)
{
viewModel.RefreshSync();
foreach (var entityScreenItemViewModel in viewModel.ResourceSelectorViewModel.EntityScreenItems)
{
entityScreenItemViewModel.IsEnabled = false;
}
}
var ret = new EntitySelectorView(viewModel.ResourceSelectorViewModel) { DataContext = viewModel.ResourceSelectorViewModel, ContextMenu = contextMenu, Tag = widget };
var heightBinding = new Binding("Height") { Source = viewModel, Mode = BindingMode.TwoWay };
var widthBinding = new Binding("Width") { Source = viewModel, Mode = BindingMode.TwoWay };
var xBinding = new Binding("X") { Source = viewModel, Mode = BindingMode.TwoWay };
var yBinding = new Binding("Y") { Source = viewModel, Mode = BindingMode.TwoWay };
ret.SetBinding(InkCanvas.LeftProperty, xBinding);
ret.SetBinding(InkCanvas.TopProperty, yBinding);
ret.SetBinding(FrameworkElement.HeightProperty, heightBinding);
ret.SetBinding(FrameworkElement.WidthProperty, widthBinding);
return ret;
}
示例6: AddContextMenu
protected void AddContextMenu()
{
ContextMenu mainMenu = new ContextMenu();
MenuItem item1 = new MenuItem() { Header = "Copy to Clipboard" };
mainMenu.Items.Add(item1);
MenuItem item1a = new MenuItem();
item1a.Header = "96 dpi";
item1.Items.Add(item1a);
item1a.Click += OnClipboardCopy_96dpi;
MenuItem item1b = new MenuItem();
item1b.Header = "300 dpi";
item1.Items.Add(item1b);
item1b.Click += OnClipboardCopy_300dpi;
MenuItem item1c = new MenuItem() { Header = "Enhanced Metafile" }; ;
item1.Items.Add(item1c);
item1c.Click += CopyToEMF;
//MenuItem item2 = new MenuItem() { Header = "Print..." };
//mainMenu.Items.Add(item2);
//item2.Click += InvokePrint;
windowsFormsHost.ContextMenu = mainMenu;
}
示例7: MainWindow
public MainWindow()
{
// ColorBrewer2 Set1
defaultColors.Add(Color.FromRgb(228, 26, 28));
defaultColors.Add(Color.FromRgb(55, 126, 184));
defaultColors.Add(Color.FromRgb(77, 175, 74));
defaultColors.Add(Color.FromRgb(152, 78, 163));
defaultColors.Add(Color.FromRgb(255, 127, 0));
defaultColors.Add(Color.FromRgb(255, 255, 51));
defaultColors.Add(Color.FromRgb(166, 86, 40));
defaultColors.Add(Color.FromRgb(247, 129, 191));
defaultColors.Add(Color.FromRgb(153, 153, 153));
LoadCellGroups();
this.InitializeComponent();
// Insert code required on object creation below this point.
// Setting default color picker style
colorMenu = (ContextMenu)(this.Resources["leftClickHSVMenu"]);
// colorMenu = (ContextMenu)(this.Resources["leftClickRGBMenu"]);
// Should be able to do this in the xaml...
CollectionViewSource ldv = this.Resources["listingDataView"] as CollectionViewSource;
if (ldv != null)
{
ldv.Source = CellConfigItems;
}
}
示例8: ExtendWithContextMenu
public static void ExtendWithContextMenu(this TextEditor rtb)
{
ContextMenu ctx = new ContextMenu();
MenuItem cut = new MenuItem();
cut.Header = "Cut";
cut.Click += (sender, e) => rtb.Cut();
MenuItem copy = new MenuItem();
copy.Header = "Copy";
copy.Click += (sender, e) => rtb.Copy();
MenuItem paste = new MenuItem();
paste.Header = "Paste";
paste.Click += (sender, e) => rtb.Paste();
ctx.Items.Add(cut);
ctx.Items.Add(copy);
ctx.Items.Add(paste);
rtb.ContextMenu = ctx;
ctx.Opened +=
(sender, e) =>
{
bool noSelectedText = string.IsNullOrEmpty(rtb.SelectedText);
cut.IsEnabled = !noSelectedText;
copy.IsEnabled = !noSelectedText;
bool noClipboardText = string.IsNullOrEmpty(Clipboard.GetText());
paste.IsEnabled = !noClipboardText;
};
}
示例9: AudioCanvas
public AudioCanvas()
{
/* The background must be set for the canvas mouse interaction to work properly,
* otherwise the mouse events will fall through to the control "underneath" this one.
*/
Background = Brushes.Transparent;
_spaceImage = new Image();
_waveformImage = new Image();
//Add the two images in this over so that _space image is drawn over _waveformImage
Children.Add(_waveformImage);
Children.Add(_spaceImage);
/* This method contains a null reference in the designer, causing an exception and not
* rendering the canvas. This check guards against it.
*/
if (!DesignerProperties.GetIsInDesignMode(this))
SetBrushes();
MouseSelection = CanvasMouseSelection.NoSelection;
ContextMenu = new ContextMenu();
InitEventHandlers();
}
示例10: MainWindowContextMenuOpening
private void MainWindowContextMenuOpening(object sender, ContextMenuEventArgs e)
{
var fe = sender as FrameworkElement;
var _scriptingUIHelper = CompositionManager.Get<IScriptingUIHelper>();
var _scriptingConfiguration = CompositionManager.Get<IScriptingConfiguration>();
if (fe == null)
return;
var newcontextualmenu = new ContextMenu();
if (_scriptingUIHelper != null)
{
List<object> menu = _scriptingUIHelper.CreateContextMenusFromScripts(false,
_scriptingConfiguration.
MainWindowContextMenuEntryPoint,
MenuItemClick);
if (menu != null)
{
foreach (object i in menu)
newcontextualmenu.Items.Add(i);
}
}
fe.ContextMenu = newcontextualmenu;
}
示例11: DesignerCanvas
public DesignerCanvas(PlanDesignerViewModel planDesignerViewModel)
: base(ServiceFactoryBase.Events)
{
GridLineController = new GridLineController(this);
RemoveGridLinesCommand = new RelayCommand(OnRemoveGridLinesCommand);
PlanDesignerViewModel = planDesignerViewModel;
Toolbox = new ToolboxViewModel(this);
ServiceFactoryBase.DragDropService.DragOver += OnDragServiceDragOver;
ServiceFactoryBase.DragDropService.Drop += OnDragServiceDrop;
PainterCache.Initialize(ServiceFactoryBase.ContentService.GetBitmapContent, ServiceFactoryBase.ContentService.GetDrawing);
Width = 100;
Height = 100;
Focusable = false;
DesignerSurface.AllowDrop = true;
var menuItem = DesignerCanvasHelper.BuildMenuItem(
"Вставить (Ctrl+V)",
"pack://application:,,,/Controls;component/Images/BPaste.png",
PlanDesignerViewModel.PasteCommand
);
menuItem.CommandParameter = this;
var pasteItem = menuItem;
ContextMenu = new ContextMenu();
ContextMenu.HasDropShadow = false;
ContextMenu.Items.Add(pasteItem);
_moveAdorner = new MoveAdorner(this);
}
示例12: OptionsMenu
public OptionsMenu()
{
InitializeComponent();
ContextMenu = new ContextMenu();
button.Click += (s, e) => ShowOptions();
}
示例13: AttachContextMenu
private void AttachContextMenu(object sender, MouseButtonEventArgs e) {
//this is PreviewMouseRightButtonDown on StackPanel in TreeView
e.Handled = true;
StackPanel stackPanel = (StackPanel) sender;
object item = stackPanel.DataContext;
if (stackPanel.ContextMenu != null) return;
ContextMenu menu = new ContextMenu {Tag = item};
switch (item.GetType().Name) {
case nameof(ViewModel.Folders): {
menu.Items.Add(new MenuItem {Command = (ICommand) Resources["FolderAdd"], CommandParameter = item});
break;
}
case nameof(ViewModel.Folder): {
if (((ViewModel.Folder) item).Parent == null) {
menu.Items.Add(new MenuItem {Command = (ICommand) Resources["FolderRemove"], CommandParameter = item});
}
break;
}
}
if (menu.Items.Count > 0)
stackPanel.ContextMenu = menu;
}
示例14: AddMenuItem
private static void AddMenuItem(ContextMenu menu, string text, string shortcut, EventHandler handler)
{
var item = new MenuItem();
item.Header = text;
item.Click += (s, e) => handler(s, e);
menu.Items.Add(item);
}
示例15: VideoCM
private ContextMenu VideoCM()
{
var cm = new ContextMenu();
cm.Items.Add(ContextMenuItems.Play(PlayVideo));
cm.Items.Add(ContextMenuItems.Stop(StopVideo));
return cm;
}