sourcechord/FluentWPF

Fluent Design in Windows 11

sourcechord opened this issue · 11 comments

FluentWPF has some problems in Windows 11.

Please comment in this issue about Fluent Design in Windows 11.

Rollback to version 0.9 and everything work fine, included:

  1. Animation of the maximized window to normal window.
  2. Animation of the normal window to maximized window.
  3. Animation of the minimized window to maximized / normal window.
  4. Animation of the maximized / normal window to minimized window.
  5. Acrylic screen.
  6. DragMove.
  7. MinHeight and MinWidth

Works well on Windows 11.

Facts:
QQ截图20211015212410

without page

QQ截图20211015212423

with the page (attention title bar)

Does ACRYLICBLURBEHIND not work at all on Windows 11?
Any way to fix this?

logue commented

When using Fluent Wpf with MahApps, there was a lag when moving the semi-transparent window, but when using Fluent WPF with Modern WPF, it worked without any problems.

Actually found an easy way to apply Mica to a window in WPF:
image
PS it also supports snap grids:
image

public enum WindowsTheme
{
	Light,
	Dark
}

public class ThemeHelper
{
	private const string _registryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";

	private const string _registryValueName = "AppsUseLightTheme";


	public static WindowsTheme GetWindowsTheme()
	{

        using RegistryKey? key = Registry.CurrentUser.OpenSubKey(_registryKeyPath);
        object? registryValueObject = key?.GetValue(_registryValueName);
        if (registryValueObject == null)
        {
            return WindowsTheme.Light;
        }

        int registryValue = (int)registryValueObject;

        return registryValue > 0 ? WindowsTheme.Light : WindowsTheme.Dark;
    }
}

public static class MicaHelper
{
    [DllImport("dwmapi.dll")]
    private static extern int DwmSetWindowAttribute(IntPtr hwnd, DwmWindowAttribute dwAttribute, ref int pvAttribute, int cbAttribute);

    [Flags]
    private enum DwmWindowAttribute : uint
    {
        DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
        DWMWA_MICA_EFFECT = 1029
    }

    public static void UpdateStyleAttributes(this Window window)
    {
        IntPtr windowHandle = new WindowInteropHelper(window).Handle;
        var darkThemeEnabled = ThemeHelper.GetWindowsTheme();

        int trueValue = 0x01;
        int falseValue = 0x00;

        if (darkThemeEnabled == WindowsTheme.Dark)
        {
            _ = DwmSetWindowAttribute(windowHandle, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref trueValue, Marshal.SizeOf(typeof(int)));
        }
        else
        {
            _ = DwmSetWindowAttribute(windowHandle, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref falseValue, Marshal.SizeOf(typeof(int)));
        }

        _ = DwmSetWindowAttribute(windowHandle, DwmWindowAttribute.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
    }
}

Usage:
Window code behind:

    public MainWindow()
    {
        this.UpdateStyleAttributes();
    }

Window Xaml:

<Window x:Class="WpfTest01.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:local="clr-namespace:WpfTest01"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        Background="Transparent">
    <WindowChrome.WindowChrome>
        <WindowChrome
            CaptionHeight="20"
            ResizeBorderThickness="8"
            CornerRadius="0"
            GlassFrameThickness="-1"
            UseAeroCaptionButtons="True" />
    </WindowChrome.WindowChrome>
    <Grid>

    </Grid>
</Window>

same issue

I was able to get an ACRYLICBLURBEHIND working under Windows 11 by not setting accent.AccentFlags = 2 and by setting the WindowStyle="None" along with fw:AcrylicWindow.AllowsTransparency="True". Here is a branch with a modified sample app with the working Acrylic window: https://github.com/cfoucher/FluentWPF/tree/win11_acrylicBlur

image

Roll back to version 0.9, and acrylic effect can work normally. However, there are some problems, such as dragging the window slowly and window flashing when dragging the window.

ACRYLICBLURBEHIND is working just fine on Windows 11. I was able to make acrylic menu/popup with it.

image

The only disadvantage is that there are no fancy slide animations on popup opening. They just do not work :(

@sourcechord can you update?