Repository navigation
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
62 lines (52 loc) · 1.82 KB
/
Copy pathMainPage.xaml.cs
File metadata and controls
62 lines (52 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Windows.System;
using Lexorio.ViewModels;
namespace Lexorio;
public sealed partial class MainPage : Page
{
public MainViewModel ViewModel { get; }
public MainPage()
{
ViewModel = App.ViewModel
?? throw new InvalidOperationException("App.ViewModel is not initialized.");
InitializeComponent();
ViewModel.Settings.ConfirmHistoryClear = ConfirmHistoryClearAsync;
}
private async Task<bool> ConfirmHistoryClearAsync(int count)
{
var dialog = new ContentDialog
{
XamlRoot = XamlRoot,
Title = "Clear older history?",
Content = $"{count} history entries older than the chosen period will be deleted now. This cannot be undone.",
PrimaryButtonText = "Delete",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Close
};
return await dialog.ShowAsync() == ContentDialogResult.Primary;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is MainViewModel vm && !ReferenceEquals(vm, ViewModel))
{
// App.ViewModel is the source of truth; parameter should match.
}
DataContext = ViewModel;
base.OnNavigatedTo(e);
}
private void WriteInstruction_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key != VirtualKey.Enter || e.KeyStatus.WasKeyDown)
{
return;
}
e.Handled = true;
if (ViewModel.Write.IsBusy || !ViewModel.Write.GenerateCommand.CanExecute(null))
{
return;
}
ViewModel.Write.GenerateCommand.Execute(null);
}
}