lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.73k stars 756 forks source link

SizeToContent and ExtendsContentIntoTitleBar #1174

Open Apskalle opened 4 months ago

Apskalle commented 4 months ago

Describe the bug

Not really a (wpfui-) bug but setting ExtendsContentIntoTitleBar to true and setting SizeToContent to WidthAndHeight gives the strange effect of the content being misaligned in the window, leaving a black area right and bottom, as described here

image

Since this rates to be common using FluentWindow, maybe a fix can be included there.

Meanwhile, a fix that seems to work but gives som flicker: In the windows ContentRendered call

private void corewnd_ContentRendered(object sender, System.EventArgs e)
  {
      var firstrender = true;

      if (firstrender)
      {
          InvalidateVisual();
          firstrender = false;
      }
}

To Reproduce

Set FluentWindow ExtendsContentIntoTitleBar=true and WidthAndHeight=SizeToContent and add content.

Expected behavior

Normal content display

Screenshots

No response

OS version

Win 11 Pro

.NET version

8

WPF-UI NuGet version

4.0.3

Additional context

No response

Apskalle commented 3 months ago

Additional:

<ui:FluentWindow x:Class="WpfNet9App.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
        xmlns:local="clr-namespace:WpfNet9App"
        mc:Ignorable="d"
        ExtendsContentIntoTitleBar="True"        
        SizeToContent="WidthAndHeight"         
        Title="MainWindow">
    <Grid>
        <Border Width="300" Height="300" Background="Yellow"/>
    </Grid>

</ui:FluentWindow>

In VS preview window:

image

When run:

image

Apskalle commented 3 months ago

The Wpf source shows MS have been looking at this, as far as I can tell w/o really fixing it

From comment in https://github.com/dotnet/wpf/tree/main/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs, line 2557

// We don't do anything that uses the Window styles below so we might as // well close the using so that we update the new style to the hwnd. // This change was made to solve a problem where SizeToContent.WidthAndHeight borderless // windows where actually bigger than the content size. This was b/c of // the fact that we didn't update the style of the hwnd before setting // the RootVisual which inturn calls MeasureOverride on Window from // where we calculating the non-client area size using the stale // style bits from the hwnd.