using System.ComponentModel; using System.Windows; using System.Windows.Controls; namespace Intromat.Views { /// /// Interaction logic for UserInputWindow.xaml /// public partial class UserInputWindow { public UserInputWindow() { InitializeComponent(); } public string? Result { get; set; } public static string? Show(Window? owner, string? header, string? title = null, string? defaultValue = null) { var window = new UserInputWindow { Owner = owner, Title = title ?? "Intromat", Header = { Text = header ?? "Enter value:" } }; if (defaultValue != null) window.Input.Text = window.Result = defaultValue; window.Input.SelectAll(); window.Input.Focus(); return window.ShowDialog() == true ? window.Result : null; } private void Input_OnTextChanged(object sender, TextChangedEventArgs e) { Result = Input.Text; } private void ButtonOK_OnClick(object sender, RoutedEventArgs e) { DialogResult = true; Close(); } private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) { DialogResult = false; Close(); } private void UserInputWindow_OnClosing(object sender, CancelEventArgs e) { if (DialogResult != true) Result = null; } } }