Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wpf: Remove border around resizable borderless windows #2344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/Eto.Wpf/Forms/WpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ protected override void Initialize()

private void Control_Loaded(object sender, sw.RoutedEventArgs e)
{
if (WindowStyle == WindowStyle.None)
{
SetWindowChrome(true);
}

if (!Minimizable || !Maximizable)
{
SetResizeMode();
Expand Down Expand Up @@ -861,7 +866,51 @@ public override bool HasFocus
public WindowStyle WindowStyle
{
get { return Control.WindowStyle.ToEto(); }
set { Control.WindowStyle = value.ToWpf(); }
set
{
if (WindowStyle != value)
{
Control.WindowStyle = value.ToWpf();
SetWindowChrome(value == WindowStyle.None);
}
}
}

void SetWindowChrome(bool enabled)
{
if (!Control.IsLoaded)
return;
// Annoyingly, WPF gets an AritheticOverflow if the window style has WS_POPUP in it as it treats it as an int
// So, we remove that style then re-apply it after.
uint? oldStyle = null;
var style = Win32.GetWindowLong(NativeHandle, Win32.GWL.STYLE);
if (style > (uint)Int32.MaxValue)
{
// style will overflow, so remove the last bit
oldStyle = style & (uint)(0x80000000);
Win32.SetWindowLong(NativeHandle, Win32.GWL.STYLE, style & 0x7FFFFFFF);
}
if (enabled)
{
var windowChrome = new sw.Shell.WindowChrome
{
CaptionHeight = 0,
ResizeBorderThickness = new sw.Thickness(4)
};
sw.Shell.WindowChrome.SetWindowChrome(Control, windowChrome);
}
else
{
Control.ClearValue(sw.Shell.WindowChrome.WindowChromeProperty);
}

if (oldStyle != null)
{
// reapply the old style bit
style = Win32.GetWindowLong(NativeHandle, Win32.GWL.STYLE);
style |= oldStyle.Value;
Win32.SetWindowLong(NativeHandle, Win32.GWL.STYLE, style);
}
}

public void BringToFront()
Expand Down
3 changes: 3 additions & 0 deletions test/Eto.Test/Sections/Behaviors/WindowsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ protected override void OnUnLoad(EventArgs e)
MenuBar CreateMenuBar()
{
var menu = new MenuBar();
menu.Items.Add(new SubMenuItem { Text = "&File", Items = {
new ButtonMenuItem { Text = "Click Me" }
}});
if (systemMenuItems.SelectedValues.Any())
menu.IncludeSystemItems = GetMenuItems();
return menu;
Expand Down