11using System ;
2+ using System . IO ;
23using Microsoft . UI . Xaml ;
4+ using Microsoft . UI . Xaml . Markup ;
35
46namespace UnoEdit . WinUI . Sample ;
57
@@ -16,61 +18,11 @@ public App()
1618
1719 private void LoadUnoEditorResources ( )
1820 {
19- var dict = new Microsoft . UI . Xaml . ResourceDictionary ( ) ;
20-
21- // Scalar resources
22- dict [ "UnoTextEditorBorderThickness" ] = new Microsoft . UI . Xaml . Thickness ( 1 ) ;
23- dict [ "UnoTextEditorCornerRadius" ] = new Microsoft . UI . Xaml . CornerRadius ( 10 ) ;
24- dict [ "UnoSearchPanelCornerRadius" ] = new Microsoft . UI . Xaml . CornerRadius ( 8 ) ;
25- dict [ "UnoSearchPanelMargin" ] = new Microsoft . UI . Xaml . Thickness ( 12 , 12 , 12 , 0 ) ;
26- dict [ "UnoSearchPanelPadding" ] = new Microsoft . UI . Xaml . Thickness ( 10 ) ;
27- dict [ "UnoEditorLineHeight" ] = 22.0 ;
28- dict [ "UnoEditorTextFontSize" ] = 13.0 ;
29- dict [ "UnoEditorGlyphFontSize" ] = 10.0 ;
30- dict [ "UnoEditorOverlayHeight" ] = 16.0 ;
31- dict [ "UnoEditorCaretWidth" ] = 2.0 ;
32-
33- // Dark theme
34- var dark = new Microsoft . UI . Xaml . ResourceDictionary ( ) ;
35- dark [ "UnoEditorBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x0F , 0x17 , 0x2A ) ) ;
36- dark [ "UnoEditorBorderBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x33 , 0x41 , 0x55 ) ) ;
37- dark [ "UnoEditorTitleBarBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x0F , 0x17 , 0x2A ) ) ;
38- dark [ "UnoEditorTitleBarForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xE5 , 0xE7 , 0xEB ) ) ;
39- dark [ "UnoEditorSummaryForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x94 , 0xA3 , 0xB8 ) ) ;
40- dark [ "UnoEditorGutterForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x64 , 0x74 , 0x8B ) ) ;
41- dark [ "UnoSearchPanelBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x17 , 0x20 , 0x33 ) ) ;
42- dark [ "UnoSearchPanelBorderBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x33 , 0x41 , 0x55 ) ) ;
43- dark [ "UnoSearchPanelResultsBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x94 , 0xA3 , 0xB8 ) ) ;
44- dict . ThemeDictionaries [ "Dark" ] = dark ;
45-
46- // Light theme
47- var light = new Microsoft . UI . Xaml . ResourceDictionary ( ) ;
48- light [ "UnoEditorBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xFF , 0xFF , 0xFF ) ) ;
49- light [ "UnoEditorBorderBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xD1 , 0xD5 , 0xDB ) ) ;
50- light [ "UnoEditorTitleBarBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xF9 , 0xFA , 0xFB ) ) ;
51- light [ "UnoEditorTitleBarForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x11 , 0x18 , 0x27 ) ) ;
52- light [ "UnoEditorSummaryForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x6E , 0x76 , 0x81 ) ) ;
53- light [ "UnoEditorGutterForegroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x6E , 0x76 , 0x81 ) ) ;
54- light [ "UnoSearchPanelBackgroundBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xF3 , 0xF4 , 0xF6 ) ) ;
55- light [ "UnoSearchPanelBorderBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0xD1 , 0xD5 , 0xDB ) ) ;
56- light [ "UnoSearchPanelResultsBrush" ] = new Microsoft . UI . Xaml . Media . SolidColorBrush ( Microsoft . UI . ColorHelper . FromArgb ( 0xFF , 0x6E , 0x76 , 0x81 ) ) ;
57- dict . ThemeDictionaries [ "Light" ] = light ;
21+ string resourcePath = Path . Combine ( AppContext . BaseDirectory , "UnoEditorResources.xaml" ) ;
22+ string resourceXaml = File . ReadAllText ( resourcePath ) ;
23+ var dict = ( ResourceDictionary ) XamlReader . Load ( resourceXaml ) ;
5824
5925 this . Resources . MergedDictionaries . Add ( dict ) ;
60-
61- // Styles (must be added after theme resources so ThemeResource refs resolve)
62- var btnStyle = new Microsoft . UI . Xaml . Style ( typeof ( Microsoft . UI . Xaml . Controls . Button ) ) ;
63- btnStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . Controls . Button . MinWidthProperty , 44.0 ) ) ;
64- btnStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . Controls . Button . MinHeightProperty , 32.0 ) ) ;
65- this . Resources [ "UnoSearchActionButtonStyle" ] = btnStyle ;
66-
67- var cbStyle = new Microsoft . UI . Xaml . Style ( typeof ( Microsoft . UI . Xaml . Controls . CheckBox ) ) ;
68- cbStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . FrameworkElement . VerticalAlignmentProperty , Microsoft . UI . Xaml . VerticalAlignment . Center ) ) ;
69- cbStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . FrameworkElement . MarginProperty , new Microsoft . UI . Xaml . Thickness ( 0 , 2 , 0 , 0 ) ) ) ;
70- cbStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . FrameworkElement . MinHeightProperty , 0.0 ) ) ;
71- cbStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . FrameworkElement . MinWidthProperty , 0.0 ) ) ;
72- cbStyle . Setters . Add ( new Microsoft . UI . Xaml . Setter ( Microsoft . UI . Xaml . Controls . Control . PaddingProperty , new Microsoft . UI . Xaml . Thickness ( 6 , 0 , 0 , 0 ) ) ) ;
73- this . Resources [ "UnoSearchOptionCheckBoxStyle" ] = cbStyle ;
7426 }
7527
7628 protected override void OnLaunched ( LaunchActivatedEventArgs args )
@@ -96,18 +48,14 @@ private static void OnUnhandledException(object sender, Microsoft.UI.Xaml.Unhand
9648
9749 private static void OnDomainException ( object sender , System . UnhandledExceptionEventArgs e )
9850 {
99- var msg = $ "[DOMAIN] { e . ExceptionObject } ";
100- System . Diagnostics . Debug . WriteLine ( msg ) ;
101- Console . Error . WriteLine ( msg ) ;
102- System . IO . File . AppendAllText ( "crash.log" , msg + "\n " ) ;
51+ System . Diagnostics . Debug . WriteLine ( $ "[DOMAIN] { e . ExceptionObject } ") ;
52+ Console . Error . WriteLine ( $ "Fatal: { e . ExceptionObject } ") ;
10353 }
10454
10555 private static void ShowFatal ( Exception ex )
10656 {
107- var msg = $ "Fatal during launch: { ex } ";
108- System . Diagnostics . Debug . WriteLine ( msg ) ;
109- Console . Error . WriteLine ( msg ) ;
110- System . IO . File . AppendAllText ( "crash.log" , msg + "\n " ) ;
57+ System . Diagnostics . Debug . WriteLine ( $ "[FATAL] { ex } ") ;
58+ Console . Error . WriteLine ( $ "Fatal during launch: { ex } ") ;
11159 // Show a simple WinUI dialog — create a minimal window just for the message.
11260 var w = new Microsoft . UI . Xaml . Window ( ) ;
11361 var tb = new Microsoft . UI . Xaml . Controls . TextBlock
0 commit comments