public MessageBoxViewModel(Window window, string messageBoxText, string title = "", MessageBoxType messageBoxType = MessageBoxType.Ok) { this.window = window; Title = title; MessageBoxText = messageBoxText; MessageBoxType = messageBoxType; if (MessageBoxType == MessageBoxType.Ok) { OkCommand.Subscribe(_ => { this.window.Close(true); }); } else if (MessageBoxType == MessageBoxType.YesNo) { YesCommand.Subscribe(_ => { this.window.Close(true); }); NoCommand.Subscribe(_ => { this.window.Close(false); }); } }
public AskDialog() { CommandBindings.AddRange(new[] { new CommandBinding(RoutedYesCommand, (s, e) => { if (YesCommand == null) { return; } YesCommand.Execute(null); }, (s, e) => { e.CanExecute = true; }), new CommandBinding(RoutedNoCommand, (s, e) => { if (NoCommand == null) { return; } NoCommand.Execute(null); }, (s, e) => { e.CanExecute = true; }), }); }
/// <summary> /// 处理KEY /// </summary> /// <param name="args"></param> internal void HandleKey(KeyEventArgs args) { // 如果是功能(如上下左右,换页) if (args.Key == Key.Right || args.Key == Key.Left) { if (args.Key == Key.Right && AlertMsgImageMode == 4 && SelectedMode == 1) { SelectedMode = 2; } else if (args.Key == Key.Left && AlertMsgImageMode == 4 && SelectedMode == 2) { SelectedMode = 1; } } // 如果要增加数量或减少数量 if (args.Key == Key.Escape || args.Key == Key.Enter) { if (AlertMsgButtonMode == 1) { OKCommand.Execute(null); } else if (AlertMsgButtonMode == 2) { if (args.Key == Key.Escape) { NoCommand.Execute(null); } else if (args.Key == Key.Enter) { if (SelectedMode == 1) { NoCommand.Execute(null); } else if (SelectedMode == 2) { YesCommand.Execute(null); } } } } }
public ConfirmDialogViewModel() { YesCommand.Subscribe(() => RequestClose?.Invoke(new DialogResult(ButtonResult.Yes))); NoCommand.Subscribe(() => RequestClose?.Invoke(new DialogResult(ButtonResult.No))); }