55using System . IO ;
66using System . Runtime . InteropServices ;
77using System . Windows ;
8+ using System . Windows . Controls ;
89using System . Windows . Interop ;
910using System . Windows . Media ;
1011using System . Windows . Media . Imaging ;
@@ -26,6 +27,11 @@ public class BlazorDesktopWindow : Window
2627 /// </summary>
2728 public BlazorWebView WebView { get ; }
2829
30+ /// <summary>
31+ /// The <see cref="Border"/> for the <see cref="BlazorWebView"/>.
32+ /// </summary>
33+ public Border WebViewBorder { get ; }
34+
2935 /// <summary>
3036 /// The service provider.
3137 /// </summary>
@@ -74,13 +80,15 @@ public class BlazorDesktopWindow : Window
7480 public BlazorDesktopWindow ( IServiceProvider services , IConfiguration config , IWebHostEnvironment environment )
7581 {
7682 WebView = new BlazorWebView ( ) ;
83+ WebViewBorder = new Border ( ) ;
7784 _services = services ;
7885 _config = config ;
7986 _environment = environment ;
8087 _uiSettings = new UISettings ( ) ;
8188
8289 InitializeWindow ( ) ;
83- InitializeBlazor ( ) ;
90+ InitializeWebViewBorder ( ) ;
91+ InitializeWebView ( ) ;
8492 InitializeTheming ( ) ;
8593 }
8694
@@ -96,13 +104,24 @@ private void InitializeWindow()
96104 UseFrame ( _config . GetValue < bool ? > ( WindowDefaults . Frame ) ?? true ) ;
97105 ResizeMode = ( _config . GetValue < bool ? > ( WindowDefaults . Resizable ) ?? true ) ? ResizeMode . CanResize : ResizeMode . NoResize ;
98106 UseIcon ( _config . GetValue < string ? > ( WindowDefaults . Icon ) ?? string . Empty ) ;
99- Content = WebView ;
107+ Content = WebViewBorder ;
108+ StateChanged += WindowStateChanged ;
100109 }
101110
102111 /// <summary>
103- /// Initializes blazor .
112+ /// Initializes the web view border .
104113 /// </summary>
105- private void InitializeBlazor ( )
114+ private void InitializeWebViewBorder ( )
115+ {
116+ WebViewBorder . Name = "BlazorDesktopWebViewBorder" ;
117+ WebViewBorder . BorderThickness = new Thickness ( 0 , 0 , 0 , 0 ) ;
118+ WebViewBorder . Child = WebView ;
119+ }
120+
121+ /// <summary>
122+ /// Initializes the web view.
123+ /// </summary>
124+ private void InitializeWebView ( )
106125 {
107126 WebView . Name = "BlazorDesktopWebView" ;
108127 WebView . HostPage = Path . Combine ( _environment . WebRootPath , "index.html" ) ;
@@ -130,6 +149,25 @@ private void InitializeTheming()
130149 _uiSettings . ColorValuesChanged += ThemeChanged ;
131150 }
132151
152+ /// <summary>
153+ /// Occurs when the window state changes.
154+ /// </summary>
155+ /// <param name="sender">The sending object.</param>
156+ /// <param name="e">The arguments.</param>
157+ private void WindowStateChanged ( object ? sender , EventArgs e )
158+ {
159+ var useFrame = _config . GetValue < bool ? > ( WindowDefaults . Frame ) ?? true ;
160+
161+ if ( WindowState == WindowState . Maximized && ! useFrame )
162+ {
163+ WebViewBorder . BorderThickness = new Thickness ( 8 , 8 , 8 , 0 ) ;
164+ }
165+ else
166+ {
167+ WebViewBorder . BorderThickness = new Thickness ( 0 , 0 , 0 , 0 ) ;
168+ }
169+ }
170+
133171 /// <summary>
134172 /// Occurs when the window source has initialized.
135173 /// </summary>
0 commit comments