microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.2k stars 669 forks source link

[WASDK 1.3]CornerRadius on Window is 0 when IsResizable = false and SetBorderAndTitleBar() used #8374

Open TRadigk opened 1 year ago

TRadigk commented 1 year ago

Describe the bug

Dear WinUI developers,

the following code produces a window with CornerRadius = 0 (visible, I don't know how to read the value programmatically):

public MainWindow()
{
    this.InitializeComponent();
    var appWindow = GetAppWindowFromWindow(this);
    appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
    var windowPresenter = (appWindow.Presenter as OverlappedPresenter);
    windowPresenter.SetBorderAndTitleBar(true, false);
    windowPresenter.IsResizable = false;
}

using following nugets:

  <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230228005-preview1" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25336-preview" />
    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>

Also the window looks borderless:

grafik

Reproduction code here

Setting IsResizable = true re-enables the CornerRadius.

grafik

Note: The results also show more inconsistencies regarding the border which should show the accent color (set to green).

Reverting to following nugets, does not show this behaviour:

  <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230118.102" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>

grafik

This is independent of net6.0 or .net7.0 but for sure Windows 11 related, since only Windows 11 supports corner radius on windows.

Steps to reproduce the bug

  1. Create new Windows Winui 3 project
  2. Get AppWindow for the window
  3. Cast the presnter of AppWindow to overlapped presenter
  4. Call windowPresenter.SetBorderAndTitleBar(true, false); (first parameter is irrelevant for this issue)
  5. Set IsResizable = false; on the window presenter
  6. Start the app and find a window with CornerRadius == 0
  7. Set IsResizable = true; on the window presenter
  8. Restart app an find a window with CornerRadius > 0

Expected behavior

The CornerRadius and the border remain untouched, as in previous WASDK release(s)

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK Preview 1: 1.3.230228005-preview1

Windows version

Windows 11 (22H2): Build 22621

Additional context

Code for reproduction provided in summary of issue.

TRadigk commented 1 year ago

Revisiting the issue today and testing with WASDK 1.4.230628000-preview1 - issue persists.

But I have to add, this issue only exists for non-packaged apps. On packaged apps the issue is not present.

The issue was introduced with 1.2.230217.4.

Testing this issue always requires to clean bin and obj folders in project manually, Visual Studio cleaning is insufficient and can reproduce wrong results.

TRadigk commented 10 months ago

workaround (and possible root cause):

add this external method to window class:

[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attribute, ref int value, int size);

Then add this code e.g. to constructor:

int cornerPreference = 2;
//DWMWA_WINDOW_CORNER_PREFERENCE is documented to have a value of 33
var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
DwmSetWindowAttribute(windowHandle, 33, ref cornerPreference, Marshal.SizeOf<int>());