Files
ReminderOrganizer/TaskWindow.xaml.cs

52 lines
1.7 KiB
C#
Raw Normal View History

#nullable enable
using System.Windows;
using System.Windows.Input;
using ReminderOrganizer.Core;
using ReminderOrganizer.Models;
using ReminderOrganizer.Services;
using ReminderOrganizer.ViewModels;
namespace ReminderOrganizer
{
public partial class TaskWindow : Window
{
private readonly TaskViewModel _viewModel;
public ReminderTask TaskResult => _viewModel.TaskResult;
/// <param name="defaultCategory">Opens a new entry as anniversary of this category (null = appointment).</param>
public TaskWindow(ReminderTask? existingTask, bool darkMode,
System.Collections.Generic.IEnumerable<Category> categories, string? defaultCategory = null)
{
InitializeComponent();
DialogAnimation.Attach(this);
Theme.Apply(Resources, darkMode);
var localizationService = (ILocalizationService)ServiceLocator.Services.GetService(typeof(ILocalizationService))!;
_viewModel = new TaskViewModel(localizationService, existingTask, defaultCategory, categories);
_viewModel.RequestClose += OnRequestClose;
DataContext = _viewModel;
Loaded += (_, _) =>
{
NameBox.Focus();
NameBox.SelectAll();
};
}
private void OnRequestClose(object? sender, bool result)
{
DialogResult = result;
Close();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.OriginalSource is not System.Windows.Controls.TextBox)
{
DragMove();
}
}
}
}