@@ -141,6 +141,11 @@ protected override void Initialize()
141
141
142
142
private void Control_Loaded ( object sender , sw . RoutedEventArgs e )
143
143
{
144
+ if ( WindowStyle == WindowStyle . None )
145
+ {
146
+ SetWindowChrome ( true ) ;
147
+ }
148
+
144
149
if ( ! Minimizable || ! Maximizable )
145
150
{
146
151
SetResizeMode ( ) ;
@@ -861,7 +866,51 @@ public override bool HasFocus
861
866
public WindowStyle WindowStyle
862
867
{
863
868
get { return Control . WindowStyle . ToEto ( ) ; }
864
- set { Control . WindowStyle = value . ToWpf ( ) ; }
869
+ set
870
+ {
871
+ if ( WindowStyle != value )
872
+ {
873
+ Control . WindowStyle = value . ToWpf ( ) ;
874
+ SetWindowChrome ( value == WindowStyle . None ) ;
875
+ }
876
+ }
877
+ }
878
+
879
+ void SetWindowChrome ( bool enabled )
880
+ {
881
+ if ( ! Control . IsLoaded )
882
+ return ;
883
+ // Annoyingly, WPF gets an AritheticOverflow if the window style has WS_POPUP in it as it treats it as an int
884
+ // So, we remove that style then re-apply it after.
885
+ uint ? oldStyle = null ;
886
+ var style = Win32 . GetWindowLong ( NativeHandle , Win32 . GWL . STYLE ) ;
887
+ if ( style > ( uint ) Int32 . MaxValue )
888
+ {
889
+ // style will overflow, so remove the last bit
890
+ oldStyle = style & ( uint ) ( 0x80000000 ) ;
891
+ Win32 . SetWindowLong ( NativeHandle , Win32 . GWL . STYLE , style & 0x7FFFFFFF ) ;
892
+ }
893
+ if ( enabled )
894
+ {
895
+ var windowChrome = new sw . Shell . WindowChrome
896
+ {
897
+ CaptionHeight = 0 ,
898
+ ResizeBorderThickness = new sw . Thickness ( 4 )
899
+ } ;
900
+ sw . Shell . WindowChrome . SetWindowChrome ( Control , windowChrome ) ;
901
+ }
902
+ else
903
+ {
904
+ Control . ClearValue ( sw . Shell . WindowChrome . WindowChromeProperty ) ;
905
+ }
906
+
907
+ if ( oldStyle != null )
908
+ {
909
+ // reapply the old style bit
910
+ style = Win32 . GetWindowLong ( NativeHandle , Win32 . GWL . STYLE ) ;
911
+ style |= oldStyle . Value ;
912
+ Win32 . SetWindowLong ( NativeHandle , Win32 . GWL . STYLE , style ) ;
913
+ }
865
914
}
866
915
867
916
public void BringToFront ( )
0 commit comments