using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Input; using RGBController2.Commands; using RGBController2.Views.Dialogs; namespace RGBController2.ViewModels.Dialogs { /// /// NewTabDialogViewModel is the view model for the NewTabDialog. /// class NewTabDialogViewModel : BaseViewModel { /// /// The NewTabDialogView /// private NewTabDialogView DialogWindow; /// /// The command used for when the user presses the add tab button. /// public ICommand AddTabCommand { get; } /// /// The device name the user has eneter on the GUI. /// private string _deviceName; public string DeviceName { get { return _deviceName; } set { _deviceName = value; } } /// /// The device type the user has selected in the GUI. /// private int _selectedDeviceType; public int SelectedDeviceType { get { return _selectedDeviceType; } set { _selectedDeviceType = value; } } /// /// True if the user enetered parameters are valid, else false. /// e.g. this will be false if the user did not select a name for the device. /// private bool _success; public bool Success { get { return _success; } } /// /// Creates a NewTabDialogViewModel used for launching the NetTabView. /// public NewTabDialogViewModel() { AddTabCommand = new ActionCommand(p => AddTab()); _success = false; } /// /// Creates window instance for this dialog viewmodel and displays it, getting the dialog result. /// public void ShowDialogWindow() { // This is a property of the DialogViewModelBase class - thus, each DialogViewModel holds a reference to its own DialogWindow: this.DialogWindow = new NewTabDialogView(); // Tell the DialogWindow to display this ViewModel: this.DialogWindow.DataContext = this; // Launch the Window, using a method of the Window baseclass, that only returns when the window is closed: this.DialogWindow.ShowDialog(); } /// /// This is the call back function used for the add button. /// public void AddTab() { // Do some validation here string errorMessage = ""; if (DeviceName == "" || DeviceName == null) errorMessage += " - Device Name cannot be left empty\n"; // Close the dialog window if validdation passes if (errorMessage == "") { _success = true; DialogWindow.Close(); } else MessageBox.Show("Validation error\n" + errorMessage); } } }