-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (49 loc) · 1.3 KB
/
Program.cs
File metadata and controls
57 lines (49 loc) · 1.3 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
using System;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace HelloWinUI;
public class App : Application
{
private Window? _window;
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var root = new Grid();
_window = new Window
{
Title = "WinUI",
Content = root,
};
root.Loaded += OnRootLoaded;
_window.Activate();
}
private async void OnRootLoaded(object sender, RoutedEventArgs e)
{
var root = (FrameworkElement)sender;
root.Loaded -= OnRootLoaded;
var dialog = new ContentDialog
{
XamlRoot = root.XamlRoot,
Title = "WinUI",
Content = $"WinUI: {typeof(Application).Name}",
CloseButtonText = "OK",
};
await dialog.ShowAsync();
_window?.Close();
Exit();
}
}
public static class Program
{
[STAThread]
public static void Main()
{
Application.Start(p =>
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
System.Threading.SynchronizationContext.SetSynchronizationContext(context);
_ = new App();
});
}
}