Files
LehrerApp/LehrerApp.Desktop/Views/Groups/AddSessionDialog.axaml.cs
T

37 lines
1011 B
C#

using Avalonia.Controls;
using Avalonia.Interactivity;
using LehrerApp.Desktop.ViewModels.Groups;
namespace LehrerApp.Desktop.Views.Groups;
public partial class AddSessionDialog : Window
{
public AddSessionDialog() => InitializeComponent();
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
if (DataContext is AddSessionDialogViewModel { IsEditing: true })
{
var commentBox = this.FindControl<TextBox>("CommentBox");
commentBox?.Focus();
commentBox?.SelectAll();
}
else
{
this.FindControl<TextBox>("DateBox")?.Focus();
}
}
private void OnSave(object? s, RoutedEventArgs e)
{
if (DataContext is AddSessionDialogViewModel vm && vm.SaveCommand.CanExecute(null))
{
vm.SaveCommand.Execute(null);
if (vm.Result is not null) Close(true);
}
}
private void OnCancel(object? s, RoutedEventArgs e) => Close(false);
}