Skip to content

Commit 835d81d

Browse files
authored
Merge pull request #2344 from cwensley/curtis/wpf-remove-resize-top-border
Wpf: Remove border around resizable borderless windows
2 parents a10614c + 8907baf commit 835d81d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/Eto.Wpf/Forms/WpfWindow.cs

+50-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ protected override void Initialize()
141141

142142
private void Control_Loaded(object sender, sw.RoutedEventArgs e)
143143
{
144+
if (WindowStyle == WindowStyle.None)
145+
{
146+
SetWindowChrome(true);
147+
}
148+
144149
if (!Minimizable || !Maximizable)
145150
{
146151
SetResizeMode();
@@ -861,7 +866,51 @@ public override bool HasFocus
861866
public WindowStyle WindowStyle
862867
{
863868
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+
}
865914
}
866915

867916
public void BringToFront()

test/Eto.Test/Sections/Behaviors/WindowsSection.cs

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ protected override void OnUnLoad(EventArgs e)
107107
MenuBar CreateMenuBar()
108108
{
109109
var menu = new MenuBar();
110+
menu.Items.Add(new SubMenuItem { Text = "&File", Items = {
111+
new ButtonMenuItem { Text = "Click Me" }
112+
}});
110113
if (systemMenuItems.SelectedValues.Any())
111114
menu.IncludeSystemItems = GetMenuItems();
112115
return menu;

0 commit comments

Comments
 (0)