/// <summary> /// Invoked when an unhandled <see cref="E:System.Windows.Input.Mouse.MouseUp"/> routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs"/> that contains the event data. The event data reports that the mouse button was released.</param> protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); switch (e.ChangedButton) { case MouseButton.Right: var mousePosition = System.Windows.Forms.Cursor.Position; var viewModel = new ContextMenuViewModel(); var currentEnabledState = ViewModel.Modification.GetComponent <EnabledComponent>().IsEnabled; viewModel.Items.Add(new ContextMenuItemViewModel { Text = currentEnabledState ? "Disable" : "Enable", ClickedHandler = HandleEnabledClicked }); viewModel.Items.Add(new ContextMenuItemViewModel { Text = "Configure" }); viewModel.Items.Add(new ContextMenuItemViewModel { Text = "About" }); var menu = new CustomContextMenu(); menu.DataContext = viewModel; menu.WindowState = WindowState.Minimized; menu.WindowState = WindowState.Normal; menu.Left = mousePosition.X; menu.Top = mousePosition.Y; menu.Show(); break; } }
public ItemViewModel(ContextMenuViewModel parent, string value) { _parent = parent; Value = value; DeleteCommand = new ActionCommand <ItemViewModel>(s => { _parent.Items.Remove(this); }); }
// Context menu protected override void AddContextMenuItems(ContextMenuItemCollection items) { base.AddContextMenuItems(items); var fixAllMenu = new ContextMenuViewModel("全部修复", FixAllCommand, false, false, false); items.Add(fixAllMenu); var rejectAllMenu = new ContextMenuViewModel("全部忽略", RejectAllCommand, true, _rejectAll, false); items.Add(rejectAllMenu); }
protected override void AddContextMenuItems(ContextMenuItemCollection items) { base.AddContextMenuItems(items); var viewMenu = new ContextMenuViewModel("查看图形", ViewCommand, false, false, false); items.Add(viewMenu); var fixMenu = new ContextMenuViewModel("修复", FixCommand, false, false, false); items.Add(fixMenu); // Seperator items.Add(null); var isChecked = CheckResult.Status == Status.Rejected; var rejectMenu = new ContextMenuViewModel("忽略", RejectCommand, true, isChecked, false); items.Add(rejectMenu); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel(IAssemblyAnalysisService analysisService, IWindowService windowService, IApplicationControlService appCtrlService) { if (IsInDesignMode) { return; } this.analysisService = analysisService; this.windowService = windowService; this.appCtrlService = appCtrlService; this.contextMenuVM = new ContextMenuViewModel(this, appCtrlService); DropAssemblyCommand = new RelayCommand <DragEventArgs>(AnalyzeDroppedAssembly); ToggleTitleBarVisibilityCommand = contextMenuVM.ToggleTitleBarVisibilityCommand; CloseApplicationCommand = contextMenuVM.CloseApplicationCommand; AnalyzeAssemblyCommand = contextMenuVM.AnalyzeAssemblyCommand; AnalyzeFolderCommand = contextMenuVM.AnalyzeFolderCommand; }
public void ShowContextMenu(IList <IDiiagramrCommand> commands, Point position) { ContextMenuViewModel.ShowContextMenu(commands, position); }