public AlertView(string title, string message, AlertViewType type, AlertViewViewModel.Button button1, AlertViewViewModel.Button button2 = null, AlertViewViewModel.Button button3 = null) { InitializeComponent(); _alert_view_view_model = new AlertViewViewModel(title, message, type, button1, this.closeCommand, button2, button3); this.DataContext = _alert_view_view_model; this.Owner = SystemApp.Current.MainWindow; }
public AlertViewViewModel(string title, string message, AlertViewType type, Button button1, Action close, Button button2 = null, Button button3 = null) { this._title = title; this._message = message; this._type = type; this._button_1 = button1; this._button_2 = button2; this._button_3 = button3; switch (_type) { case AlertViewType.INFO: { DisplayedImage = @"/res/images/info.png"; break; } case AlertViewType.OK: { DisplayedImage = @"/res/images/ok.png"; break; } case AlertViewType.WARNING: { DisplayedImage = @"/res/images/warning.png"; break; } case AlertViewType.ERROR: { DisplayedImage = @"/res/images/error.png"; break; } } if (button2 == null && button3 == null) { _button_2 = new Button(); _button_3 = new Button(); ButtonTwoVisibility = false; ButtonThreeVisibility = false; } else if (button3 == null) { _button_3 = new Button(); ButtonThreeVisibility = false; } else if (button2 == null) { _button_2 = new Button(); ButtonTwoVisibility = false; } this.CloseCommand = new AlertViewRelayCommand(() => close()); if (_button_1.button_action == null) { this.ButtonOneCommand = new AlertViewRelayCommand(() => close()); } else { this.ButtonOneCommand = new AlertViewRelayCommand(() => _button_1.button_action()); } if (_button_2.button_action == null) { this.ButtonTwoCommand = new AlertViewRelayCommand(() => close()); } else { this.ButtonTwoCommand = new AlertViewRelayCommand(() => _button_2.button_action()); } if (_button_3.button_action == null) { this.ButtonThreeCommand = new AlertViewRelayCommand(() => close()); } else { this.ButtonThreeCommand = new AlertViewRelayCommand(() => _button_3.button_action()); } }