/
App.xaml.cs
81 lines (63 loc) · 3.3 KB
/
App.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
#nullable enable
using Dark.Net;
using Dark.Net.Wpf;
using Prism.DryIoc;
using Prism.Ioc;
using RemoteDesktopServicesCertificateSelector.Managers;
using RemoteDesktopServicesCertificateSelector.Views;
using System;
using System.IO;
using System.Reflection;
using System.Windows;
namespace RemoteDesktopServicesCertificateSelector;
public partial class App {
protected override void OnStartup(StartupEventArgs e) {
DarkNet.Instance.SetCurrentProcessTheme(Theme.Auto);
// Don't enable Aero for Windows 8 and later, so the newer, nicer Metro-looking WPF theme (Aero2) is used
if (Environment.OSVersion.Version < new Version(6, 2)) {
Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = getResourceUri("PresentationFramework.Aero", "themes/Aero.NormalColor.xaml") });
}
new SkinManager().RegisterSkins(
getResourceUri("RemoteDesktopServicesCertificateSelector", "Views/Skins/Skin.Light.xaml"),
getResourceUri("RemoteDesktopServicesCertificateSelector", "Views/Skins/Skin.Dark.xaml"));
base.OnStartup(e);
}
protected override Window CreateShell() => Container.Resolve<MainWindow>();
protected override void RegisterTypes(IContainerRegistry containerRegistry) {
containerRegistry.RegisterSingleton<CertificateManager, CertificateManagerImpl>();
}
protected override void OnExit(ExitEventArgs e) {
Container.GetContainer().Dispose();
base.OnExit(e);
}
/// <exception cref="IOException">if the resource dictionary XAML file can't be found in the executing assembly</exception>
private static Uri getResourceUri(string unpackedAssemblyName, string resourceDictionaryXamlPath) {
resourceDictionaryXamlPath = Uri.EscapeUriString(resourceDictionaryXamlPath.TrimStart('/'));
unpackedAssemblyName = Uri.EscapeUriString(unpackedAssemblyName);
string executingAssembly = Uri.EscapeUriString(Assembly.GetExecutingAssembly().GetName().Name);
Uri uri;
try {
uri = new Uri($"pack://application:,,,/{executingAssembly};component/{unpackedAssemblyName}/{resourceDictionaryXamlPath}", UriKind.Absolute);
GetResourceStream(uri)?.Stream.Dispose();
return uri;
} catch (IOException) {
uri = new Uri($"pack://application:,,,/{unpackedAssemblyName};component/{resourceDictionaryXamlPath}", UriKind.Absolute);
GetResourceStream(uri)?.Stream.Dispose();
return uri;
}
}
/*protected override void OnStartup(StartupEventArgs e) {
// https://spin.atomicobject.com/2013/12/11/wpf-data-binding-debug/
PresentationTraceSources.Refresh();
PresentationTraceSources.DataBindingSource.Listeners.Add(new ConsoleTraceListener());
// PresentationTraceSources.DataBindingSource.Listeners.Add(new DebugTraceListener());
PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error;
base.OnStartup(e);
}*/
}
/*public class DebugTraceListener: TraceListener {
public override void Write(string message) { }
public override void WriteLine(string message) {
// Debugger.Break();
}
}*/