Skip to content

Commit

Permalink
Fix "Acrylic" backdrop not working
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jul 1, 2024
1 parent 6784073 commit 8620356
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 40 deletions.
4 changes: 2 additions & 2 deletions samples/Acrylic10Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
mc:Ignorable="d"
Title="Welcome!" Height="450" Width="800"
Loaded="Window_Loaded">
<ui:SimpleStackPanel VerticalAlignment="Center" Spacing="5">
<ikw:SimpleStackPanel VerticalAlignment="Center" Spacing="5">
<TextBlock Text="Legacy Acrylic API" FontSize="24" FontWeight="Bold" TextAlignment="Center"/>
<TextBlock Text="This method will enable Acrylic in Windows 10 as well." FontSize="20" TextAlignment="Center"/>

<Button Content="Hello world!" HorizontalAlignment="Center" Margin="0,20,0,0"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</Window>
16 changes: 8 additions & 8 deletions samples/FlyoutExample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<ui:SimpleStackPanel Spacing="5">
<ikw:SimpleStackPanel Spacing="5">
<TextBlock Text="Method 1" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>
<TextBlock Text="Use buttons that has a Flyout property (recommended)" FontSize="16" TextAlignment="Center" TextWrapping="Wrap" Margin="0,0,0,20"/>

<ui:SimpleStackPanel Spacing="5" Orientation="Horizontal" HorizontalAlignment="Center">
<ikw:SimpleStackPanel Spacing="5" Orientation="Horizontal" HorizontalAlignment="Center">

<ui:DropDownButton Content="Click me!">
<ui:DropDownButton.Flyout>
Expand All @@ -42,9 +42,9 @@
</ui:DropDownButton.Flyout>
</ui:DropDownButton>

</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<ui:SimpleStackPanel Margin="0,10,0,0">
<ikw:SimpleStackPanel Margin="0,10,0,0">
<ui:CommandBar HorizontalAlignment="Center">
<ui:AppBarButton Label="Click me!" ChevronStyle="Down">
<ui:AppBarButton.Icon>
Expand Down Expand Up @@ -82,11 +82,11 @@
</ui:AppBarButton>

</ui:CommandBar>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<ui:SimpleStackPanel Grid.Column="1" Spacing="5">
<ikw:SimpleStackPanel Grid.Column="1" Spacing="5">
<TextBlock Text="Method 2" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>
<TextBlock Text="Put a flyout into ikw:XamlCachedElements and open it in your c# code." FontSize="16" TextAlignment="Center" TextWrapping="Wrap"/>

Expand All @@ -98,6 +98,6 @@
</ui:Flyout>
</ikw:XamlCachedElements>

</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</Grid>
</Window>
4 changes: 2 additions & 2 deletions samples/SettingsPageExample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ResourceDictionary>
</FrameworkElement.Resources>
<ui:ScrollViewerEx>
<ui:SimpleStackPanel Spacing="10" MaxWidth="960" Margin="40" VerticalAlignment="Center">
<ikw:SimpleStackPanel Spacing="10" MaxWidth="960" Margin="40" VerticalAlignment="Center">

<TextBlock Text="Settings" FontSize="24" FontWeight="Bold"/>

Expand Down Expand Up @@ -125,6 +125,6 @@
<ui:ToggleSwitch x:Name="ToggleSwitch_StylusToDraw_Enabled" Grid.Column="2" Grid.RowSpan="2"/>
</Grid>
</Border>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ui:ScrollViewerEx>
</Window>
4 changes: 2 additions & 2 deletions samples/StarterKit/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
ui:TitleBar.Height="36"
mc:Ignorable="d"
Title="Welcome!" Height="450" Width="800">
<ui:SimpleStackPanel VerticalAlignment="Center" Spacing="5">
<ikw:SimpleStackPanel VerticalAlignment="Center" Spacing="5">
<TextBlock Text="Fluent Design is beautiful." FontSize="24" FontWeight="Bold" TextAlignment="Center"/>
<TextBlock Text="But hey, we deserve it :-)" FontSize="20" TextAlignment="Center"/>

<Button Content="Hello world!" HorizontalAlignment="Center" Margin="0,20,0,0"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</Window>
28 changes: 15 additions & 13 deletions samples/WindowExample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:local="clr-namespace:WindowExample" xmlns:sys="clr-namespace:System;assembly=netstandard"
xmlns:local="clr-namespace:WindowExample" xmlns:sys="clr-namespace:System;assembly=netstandard" xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
mc:Ignorable="d"
ui:WindowHelper.UseModernWindowStyle="True" ui:TitleBar.Height="36"
FontSize="14"
Expand All @@ -22,7 +22,7 @@

</ResourceDictionary>
</FrameworkElement.Resources>
<ui:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="20">
<ikw:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="20">
<TextBlock Text="Window Example" FontWeight="Bold" FontSize="24" TextAlignment="Center"/>
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -39,43 +39,45 @@
</Grid.RowDefinitions>

<TextBlock Text="WindowStyle" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="0" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<ikw:SimpleStackPanel Grid.Row="0" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_WindowStyle_None" Content="None" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_SingleBorder" Content="SingleBorder" MinWidth="0" IsChecked="True" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_ThreeDBorder" Content="ThreeDBorder" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_Tool" Content="Tool" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<TextBlock Text="ResizeMode" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="1" Grid.Column="1" Spacing="4" Orientation="Horizontal">
<ikw:SimpleStackPanel Grid.Row="1" Grid.Column="1" Spacing="4" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_ResizeMode_NoResize" Content="NoResize" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanMinimize" Content="CanMinimize" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanResize" Content="CanResize" MinWidth="0" IsChecked="True" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanResizeWithGrip" Content="CanResizeWithGrip" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<TextBlock Text="(ui) BackdropType" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="2" Grid.Column="1" Spacing="25" Orientation="Horizontal">
<ikw:SimpleStackPanel Grid.Row="2" Grid.Column="1" Spacing="5" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_SystemBackdropType_Acrylic" Content="Acrylic" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Acrylic11" Content="Acrylic11" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Acrylic10" Content="Acrylic10" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Mica" Content="Mica" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_None" Content="None" MinWidth="0" IsChecked="True" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Tabbed" Content="Tabbed" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<TextBlock Text="(ui) CornerStyle" Grid.Row="3" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="3" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<ikw:SimpleStackPanel Grid.Row="3" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_CornerStyle_Default" Content="Default" MinWidth="0" IsChecked="True" Click="RadioButton_CornerStyle_Click"/>
<RadioButton x:Name="RadioButton_CornerStyle_DoNotRound" Content="DoNotRound" MinWidth="0" Click="RadioButton_CornerStyle_Click"/>
<RadioButton x:Name="RadioButton_CornerStyle_Round" Content="Round" MinWidth="0" Click="RadioButton_CornerStyle_Click"/>
<RadioButton x:Name="RadioButton_CornerStyle_RoundSmall" Content="RoundSmall" MinWidth="0" Click="RadioButton_CornerStyle_Click"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>


<ui:SimpleStackPanel Grid.Row="4" Grid.ColumnSpan="2" Spacing="10" Orientation="Horizontal" Margin="10">
<ikw:SimpleStackPanel Grid.Row="4" Grid.ColumnSpan="2" Spacing="10" Orientation="Horizontal" Margin="10">
<CheckBox x:Name="CheckBox_UseModernWindowStyle" Content="(ui) ModernStyle" IsChecked="True" IsEnabled="False" Click="CheckBox_UseModernWindowStyle_Click"/>
<CheckBox x:Name="CheckBox_ApplyBackground" Content="(ui) ApplyBackground" IsChecked="False" Click="CheckBox_ApplyBackground_Click"/>
<CheckBox x:Name="CheckBox_ApplyNoise" Content="(ui) ApplyNoise" IsChecked="False" Click="CheckBox_ApplyNoise_Click"/>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>

<Grid Grid.Row="5" Grid.ColumnSpan="2" Margin="6">
<Grid.ColumnDefinitions>
Expand All @@ -101,5 +103,5 @@
</Grid>

</Grid>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</Window>
3 changes: 2 additions & 1 deletion samples/WindowExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ private void RadioButton_SystemBackdropType_Click(object sender, RoutedEventArgs
{
try
{
WindowHelper.SetSystemBackdropType(this, (BackdropType)Enum.Parse(typeof(BackdropType), val));
var backdrop = (BackdropType)Enum.Parse(typeof(BackdropType), val);
WindowHelper.SetSystemBackdropType(this, backdrop);
}
catch (Exception ex)
{
Expand Down
17 changes: 11 additions & 6 deletions source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,18 @@ private static void OnSystemBackdropTypeChanged(DependencyObject d, DependencyPr

if (d is Window window)
{
var newBackdrop = GetSystemBackdropType(window);

if (e.OldValue is BackdropType oldBackdrop &&
(oldBackdrop.GetActualBackdropType() == BackdropType.Acrylic10 || newBackdrop.GetActualBackdropType() == BackdropType.Acrylic10
&& oldBackdrop.GetActualBackdropType() != newBackdrop.GetActualBackdropType()))
{
BackdropHelper.Remove(window);
}

SetWindowStyle(window);
UpdateWindowChrome(window);
BackdropHelper.Apply(window, GetSystemBackdropType(window));
UpdateWindowChrome(window);
}
}

Expand Down Expand Up @@ -557,11 +566,7 @@ public static WindowChrome UpdateWindowChrome(this Window window)
// -----------------------------

var glassFrameThickness = new Thickness(-1);
var actualBackdrop = GetSystemBackdropType(window);

if (actualBackdrop == BackdropType.Acrylic) actualBackdrop = BackdropHelper.IsSupported(BackdropType.Acrylic11) ? BackdropType.Acrylic11 : BackdropType.Acrylic10;

switch (actualBackdrop)
switch (GetSystemBackdropType(window).GetActualBackdropType())
{
case BackdropType.None:
glassFrameThickness = new Thickness(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static bool Apply(IntPtr handle, Color color, bool force = false)
}
else
{
return TryApplyAero(handle);
return false; // TryApplyAero(handle);
}

}
Expand Down
31 changes: 27 additions & 4 deletions source/iNKORE.UI.WPF.Modern/Helpers/Styles/BackdropHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public static bool IsSupported(this BackdropType type)

return type switch
{
BackdropType.None => OSVersionHelper.OSVersion >= new Version(10, 0, 21996), // Insider with new API
BackdropType.None => true, // OSVersionHelper.OSVersion >= new Version(10, 0, 21996), // Insider with new API
BackdropType.Tabbed => OSVersionHelper.OSVersion >= new Version(10, 0, 22523),
BackdropType.Mica => OSVersionHelper.OSVersion >= new Version(10, 0, 21996),
BackdropType.Acrylic11 => OSVersionHelper.OSVersion >= new Version(10, 0, 22523),
BackdropType.Acrylic10 => true,
BackdropType.Acrylic10 => Acrylic10Helper.IsAcrylicSupported(),
BackdropType.Acrylic => IsSupported(BackdropType.Acrylic10) || IsSupported(BackdropType.Acrylic11),
_ => false
};
Expand Down Expand Up @@ -80,13 +80,19 @@ public static bool Apply(IntPtr handle, BackdropType type, bool force = false, C

if (handle == IntPtr.Zero) { return false; }

// Fixes from: https://github.com/iNKORE-NET/UI.WPF.Modern/pull/63
//var captionColor = -2; //DWMWA_COLOR_NONE - 0xFFFFFFFE
//DWMAPI.DwmSetWindowAttribute(handle, DWMAPI.DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR,
// ref captionColor,
// Marshal.SizeOf(typeof(int)));

return type switch
{
BackdropType.None => TryApplyNone(handle),
BackdropType.Mica => TryApplyMica(handle),
BackdropType.Acrylic11 => TryApplyAcrylic(handle),
BackdropType.Acrylic10 => Acrylic10Helper.TryApplyAcrylic(handle, acrylic10Color ?? Colors.Transparent),
BackdropType.Acrylic => IsSupported(BackdropType.Acrylic11) ? Apply(handle, BackdropType.Acrylic11, force, acrylic10Color) : Apply(handle, BackdropType.Acrylic10, force, acrylic10Color),
BackdropType.Acrylic => Apply(handle, GetActualBackdropType(type), force, acrylic10Color),
BackdropType.Tabbed => TryApplyTabbed(handle),
_ => false
};
Expand All @@ -105,6 +111,16 @@ public static void Remove(Window window)
Remove(windowHandle);
}

public static BackdropType GetActualBackdropType(this BackdropType type)
{
if (type == BackdropType.Acrylic)
{
return IsSupported(BackdropType.Acrylic11) ? BackdropType.Acrylic11 : BackdropType.Acrylic10;
}

return type;
}

/// <summary>
/// Tries to remove all effects if they have been applied to the <c>hWnd</c>.
/// </summary>
Expand All @@ -113,6 +129,9 @@ public static void Remove(IntPtr handle)
{
if (handle == IntPtr.Zero) return;

Acrylic10Helper.Remove(handle);


int pvAttribute = (int)DWMAPI.PvAttribute.Disable;
int backdropPvAttribute = (int)DWMAPI.DWMSBT.DWMSBT_DISABLE;

Expand All @@ -125,7 +144,11 @@ public static void Remove(IntPtr handle)
ref backdropPvAttribute,
Marshal.SizeOf(typeof(int)));

Acrylic10Helper.Remove(handle);
// Fixes from: https://github.com/iNKORE-NET/UI.WPF.Modern/pull/63
//var captionColor = -1; //DWMWA_COLOR_DEFAULT - 0xFFFFFFFF
//DWMAPI.DwmSetWindowAttribute(handle, DWMAPI.DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR,
// ref captionColor,
// Marshal.SizeOf(typeof(int)));
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion source/iNKORE.UI.WPF.Modern/Themes/Styles/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Setter Property="UseLayoutRounding" Value="True" />
<!--<Setter Property="WindowChrome.WindowChrome" Value="{DynamicResource DefaultWindowChrome}" />-->
<Setter Property="root:ThemeManager.IsThemeAware" Value="True" />
<Setter Property="chelper:WindowHelper.Acrylic10Color" Value="{DynamicResource {x:Static root:ThemeKeys.LayerFillColorDefaultKey}}"/>
<Setter Property="chelper:WindowHelper.Acrylic10Color" Value="#F9F9F9"/>
<Setter Property="primitives:TitleBar.Background" Value="{DynamicResource ControlFillColorTransparentBrush}" />
<Setter Property="primitives:TitleBar.Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="primitives:TitleBar.InactiveBackground" Value="{DynamicResource ControlFillColorTransparentBrush}" />
Expand Down Expand Up @@ -249,6 +249,10 @@
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="WindowChrome.WindowChrome" Value="{DynamicResource AeroWindowChrome}" />
<Style.Triggers>
<Trigger Property="chelper:WindowHelper.SystemBackdropType" Value="Acrylic">
<Setter Property="chelper:WindowHelper.ApplyBackground" Value="False"/>
<!--<Setter Property="chelper:WindowHelper.ApplyNoise" Value="True"/>-->
</Trigger>
<Trigger Property="chelper:WindowHelper.SystemBackdropType" Value="Acrylic10">
<Setter Property="chelper:WindowHelper.ApplyBackground" Value="False"/>
<!--<Setter Property="chelper:WindowHelper.ApplyNoise" Value="True"/>-->
Expand Down

0 comments on commit 8620356

Please sign in to comment.