-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
100 lines (92 loc) · 3.04 KB
/
MainWindow.xaml.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
namespace GraphicalMirai
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#pragma warning disable CS8618
public static MainWindow Instance { get; private set; }
#pragma warning restore CS8618
public static void Navigate(object content) => Instance.Navigate0(content);
public static void SetTitle(string title) => Instance.Title = title;
public static InnerMessageBox Msg => Instance.msgBox;
object? pageSwitchTo;
Storyboard aniSwitchPage0;
Storyboard aniSwitchPage1;
public MainWindow()
{
InitializeComponent();
DoubleAnimation aniIn = new()
{
From = 0,
To = 1,
Duration = TimeSpan.FromMilliseconds(300)
};
DoubleAnimation aniOut = new()
{
From = 1,
To = 0,
Duration = TimeSpan.FromMilliseconds(300)
};
aniOut.Completed += delegate
{
frame.Navigate(pageSwitchTo);
};
Storyboard.SetTarget(aniIn, frame);
Storyboard.SetTargetProperty(aniIn, new("Opacity"));
Storyboard.SetTarget(aniOut, frame);
Storyboard.SetTargetProperty(aniOut, new("Opacity"));
aniSwitchPage0 = new Storyboard();
aniSwitchPage1 = new Storyboard();
aniSwitchPage0.Children.Add(aniOut);
aniSwitchPage1.Children.Add(aniIn);
Instance = this;
frame.NavigationService.Navigating += (sender, e) =>
{
if (e.Uri == null) return;
if (e.Uri.Scheme == "http" || e.Uri.Scheme == "https")
{
e.Cancel = true;
App.openUrl(e.Uri.ToString());
}
};
frame.Navigate(App.PageInit);
}
private void Navigate0(object content)
{
pageSwitchTo = content;
BeginStoryboard(aniSwitchPage0);
}
private void frame_Navigated(object sender, NavigationEventArgs e)
{
object content = e.Content;
if (content != null && content is Page)
{
Title = ((Page)content).Title;
}
BeginStoryboard(aniSwitchPage1);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MinWidth = ActualWidth;
MinHeight = ActualHeight;
SizeToContent = SizeToContent.Manual;
this.Activate();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!stopping)
{
stopping = true;
App.mirai.Stop();
}
}
bool stopping = false;
}
}