本文整理汇总了C#中System.Windows.Controls.ContextMenu类的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu类的具体用法?C# ContextMenu怎么用?C# ContextMenu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextMenu类属于System.Windows.Controls命名空间,在下文中一共展示了ContextMenu类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:30,代码来源:EntityButtonWidgetCreator.cs
示例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;
}
开发者ID:yemreguney,项目名称:SambaPOS-3,代码行数:26,代码来源:TicketExplorerWidgetCreator.cs
示例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;
}
开发者ID:vincenthamm,项目名称:ATF,代码行数:34,代码来源:ContextMenuService.cs
示例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;
}
开发者ID:Neakas,项目名称:ProjectSWN,代码行数:27,代码来源:Token.cs
示例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;
}
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:29,代码来源:EntityGridWidgetCreator.cs
示例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;
}
开发者ID:goutkannan,项目名称:ironlab,代码行数:26,代码来源:MSChartHost.xaml.cs
示例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;
}
}
开发者ID:emonson,项目名称:WPFcolorPickerTest,代码行数:28,代码来源:MainWindow.xaml.cs
示例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;
};
}
开发者ID:furesoft,项目名称:IntegratedJS,代码行数:35,代码来源:Extensions.cs
示例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();
}
开发者ID:vserrago,项目名称:LiveDescribe-Desktop,代码行数:26,代码来源:AudioCanvas.cs
示例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;
}
开发者ID:nickhodge,项目名称:MahTweets.LawrenceHargrave,代码行数:26,代码来源:StreamsContainer.xaml.cs
示例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);
}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:28,代码来源:DesignerCanvas.cs
示例12: OptionsMenu
public OptionsMenu()
{
InitializeComponent();
ContextMenu = new ContextMenu();
button.Click += (s, e) => ShowOptions();
}
开发者ID:adymitruk,项目名称:storyteller,代码行数:7,代码来源:OptionsMenu.xaml.cs
示例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;
}
开发者ID:martin-holy,项目名称:PictureManager,代码行数:25,代码来源:DirectoryList.xaml.cs
示例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);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:ZoomableInlineAdornment.cs
示例15: VideoCM
private ContextMenu VideoCM()
{
var cm = new ContextMenu();
cm.Items.Add(ContextMenuItems.Play(PlayVideo));
cm.Items.Add(ContextMenuItems.Stop(StopVideo));
return cm;
}
开发者ID:undecimus,项目名称:komunikator,代码行数:7,代码来源:AddPlayVideoActionWindow.xaml.cs
示例16: OnApplyTemplate
/// <summary>
/// Called when the template is changed.
/// </summary>
public override void OnApplyTemplate()
{
// Unhook existing handlers
if (null != _splitElement)
{
_splitElement.MouseEnter -= new MouseEventHandler(SplitElement_MouseEnter);
_splitElement.MouseLeave -= new MouseEventHandler(SplitElement_MouseLeave);
_splitElement = null;
}
if (null != _contextMenu)
{
_contextMenu.Opened -= new RoutedEventHandler(ContextMenu_Opened);
_contextMenu.Closed -= new RoutedEventHandler(ContextMenu_Closed);
_contextMenu = null;
}
// Apply new template
base.OnApplyTemplate();
// Hook new event handlers
_splitElement = GetTemplateChild(SplitElementName) as UIElement;
if (null != _splitElement)
{
_splitElement.MouseEnter += new MouseEventHandler(SplitElement_MouseEnter);
_splitElement.MouseLeave += new MouseEventHandler(SplitElement_MouseLeave);
_contextMenu = ContextMenuService.GetContextMenu(_splitElement);
if (null != _contextMenu)
{
_contextMenu.Opened += new RoutedEventHandler(ContextMenu_Opened);
_contextMenu.Closed += new RoutedEventHandler(ContextMenu_Closed);
}
}
}
开发者ID:konglingjie,项目名称:arcgis-viewer-silverlight,代码行数:37,代码来源:SplitButton.cs
示例17: MainWindow
public MainWindow(IContainer container)
{
InitializeComponent();
_background = new SolidColorBrush(Color.FromRgb(0x24, 0x27, 0x28));
// _background =
// new ImageBrush(new BitmapImage(new Uri(@"Images/grid.jpg", UriKind.Relative)))
// {
// Stretch = Stretch.None,
// TileMode = TileMode.Tile,
// AlignmentX = AlignmentX.Left,
// AlignmentY = AlignmentY.Top,
// Viewport = new Rect(0, 0, 128, 128),
// ViewportUnits = BrushMappingMode.Absolute
// };
Application.Current.Resources["Dunno"] = Application.Current.Resources["Dunno1"];
var compositeNode = new CompositeNode(new NodeDispatcher("Graph Dispatcher"));// TestNodes.Test3(new NodeDispatcher("Graph Dispatcher"));
_compositeNodeViewModel = new CompositeNodeViewModel(compositeNode, new Vector(), new ControlTypesResolver());
MainNode.DataContext = _compositeNodeViewModel;
var contextMenu = new ContextMenu();
MainNode.ContextMenu = contextMenu;
var nodeTypes = container != null ? container.ResolveNamed<IEnumerable<Type>>("NodeTypes") : Enumerable.Empty<Type>();
foreach (var nodeType in nodeTypes)
{
var menuItem = new MenuItem { Header = nodeType.Name };
menuItem.Click += (sender, args) => MenuItemOnClick(nodeType, MainNode.TranslatePosition(menuItem.TranslatePoint(new Point(), this)));
contextMenu.Items.Add(menuItem);
}
}
开发者ID:misupov,项目名称:Turbina,代码行数:34,代码来源:MainWindow.xaml.cs
示例18: GetContextMenuItem
public Image GetContextMenuItem()
{
Image pb = new Image();
pb.Width = 50;
pb.Height = 50;
pb.Stretch = System.Windows.Media.Stretch.Uniform;
pb.Source = this.GetImage();
//pb.Margin = new Padding(10);
ContextMenu menu = new ContextMenu();
MenuItem actions = new MenuItem();
actions.Header = "Actions";
menu.Items.Add(actions);
foreach (string actionName in this.Template.Actions)
{
MenuItem displayAction = GameAction.Get(actionName).GetMenuItemForProp(new ActionEventArgs(Game.Instance.Player, null, this));
if (displayAction != null)
{
actions.Items.Add(displayAction);
}
}
pb.ContextMenu = menu;
ToolTip tooltip = new ToolTip();
tooltip.Content = this.Template.Description;
pb.ToolTip = tooltip;
return pb;
}
开发者ID:Tragedian-HLife,项目名称:HLife,代码行数:34,代码来源:Prop.cs
示例19: initializeContextMenus
private void initializeContextMenus()
{
MenuItem playItem = new MenuItem();
playItem.Header = "Play";
playItem.Click += PlaySongFromMenu_Click;
Separator sep = new Separator();
MenuItem removeItem = new MenuItem();
removeItem.Header = "Remove";
removeItem.Click += removeItem_Click;
allMusicMenu = new ContextMenu();
allMusicMenu.Items.Add(playItem);
allMusicMenu.Items.Add(sep);
allMusicMenu.Items.Add(removeItem);
//playlist context menu
MenuItem playlistPlayItem = new MenuItem();
playlistPlayItem.Header = "Play";
playlistPlayItem.Click += PlaySongFromMenu_Click;
Separator Playlistsep = new Separator();
MenuItem removeItemFromPlaylist = new MenuItem();
removeItemFromPlaylist.Click += removeItemFromPlaylist_Click;
removeItemFromPlaylist.Header = "Remove From Playlist";
playlistMenu = new ContextMenu();
playlistMenu.Items.Add(playlistPlayItem);
playlistMenu.Items.Add(Playlistsep);
playlistMenu.Items.Add(removeItemFromPlaylist);
}
开发者ID:zachatrocity,项目名称:hTunes,代码行数:32,代码来源:MainWindow.xaml.cs
示例20: CloseAndSelect
public void CloseAndSelect(ContextMenu menu, MenuItem menuItem)
{
menu.IsOpen = false;
TabItem newCurrent = menuItem.Tag as TabItem;
newCurrent.BringIntoView();
newCurrent.IsSelected = true;
}
开发者ID:kakesu,项目名称:Procurement,代码行数:7,代码来源:MainPageViewModel.cs
注:本文中的System.Windows.Controls.ContextMenu类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论