Files
ReminderOrganizer/InputDialog.xaml.cs

56 lines
1.6 KiB
C#
Raw Normal View History

#nullable enable
using System.Windows;
using System.Windows.Input;
using ReminderOrganizer.Core;
using ReminderOrganizer.Services;
namespace ReminderOrganizer
{
public partial class InputDialog : Window
{
public string ResponseText { get; private set; } = "";
public InputDialog(string title, string prompt, string defaultValue = "", bool? darkMode = null)
{
InitializeComponent();
DialogAnimation.Attach(this);
Title = title;
TxtTitle.Text = title;
TxtPrompt.Text = prompt;
TxtInput.Text = defaultValue;
if (ServiceLocator.Services.GetService(typeof(ILocalizationService)) is ILocalizationService loc)
{
BtnCancel.Content = loc.GetString("Cancel");
BtnOk.Content = loc.GetString("OK");
}
if (darkMode.HasValue) Theme.Apply(Resources, darkMode.Value);
Loaded += (_, _) =>
{
TxtInput.Focus();
TxtInput.SelectAll();
};
}
private void BtnOk_Click(object sender, RoutedEventArgs e)
{
ResponseText = TxtInput.Text;
DialogResult = true;
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.OriginalSource is not System.Windows.Controls.TextBox)
{
DragMove();
}
}
}
}