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

Improve/mica #135

Merged
merged 2 commits into from
Apr 7, 2022
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
2 changes: 1 addition & 1 deletion src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="WindowStyle" Value="None"/>
<Condition Property="ApplyBackdropMaterial" Value="False" />
<Condition Property="SystemBackdropType" Value="Disable" />
</MultiTrigger.Conditions>
<Setter Property="ShowNonClientArea" Value="False"/>
</MultiTrigger>
Expand Down
2 changes: 1 addition & 1 deletion src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4781,7 +4781,7 @@
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="WindowStyle" Value="None" />
<Condition Property="ApplyBackdropMaterial" Value="False" />
<Condition Property="SystemBackdropType" Value="Disable" />
</MultiTrigger.Conditions>
<Setter Property="ShowNonClientArea" Value="False" />
</MultiTrigger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HandyControl.Controls;

public static class WindowAttach
public static partial class WindowAttach
{
public static readonly DependencyProperty IsDragElementProperty = DependencyProperty.RegisterAttached(
"IsDragElement", typeof(bool), typeof(WindowAttach), new PropertyMetadata(ValueBoxes.FalseBox, OnIsDragElementChanged));
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void OnApplyTemplate()
EnableBlur(this, true);
}

private static void EnableBlur(Window window, bool isEnabled)
public static void EnableBlur(Window window, bool isEnabled)
{
var version = OSVersionHelper.GetOSVersion();
var versionInfo = new SystemVersionInfo(version.Major, version.Minor, version.Build);
Expand Down Expand Up @@ -90,7 +90,7 @@ private static void EnableBlur(Window window, bool isEnabled)
Data = accentPtr
};

InteropMethods.Gdip.SetWindowCompositionAttribute(window.GetHandle(), ref data);
InteropMethods.SetWindowCompositionAttribute(window.GetHandle(), ref data);

Marshal.FreeHGlobal(accentPtr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Attach\ListBoxAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Attach\MenuAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Attach\TreeViewAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Attach\WindowAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\BindToEnum\EnumBindingSourceExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\BindToEnum\EnumDescriptionTypeConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\BindToEnum\LocalizedDescriptionAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Windows;
using HandyControl.Tools;
namespace HandyControl.Controls
{
public static partial class WindowAttach
{
#region SystemBackdropType

public static readonly DependencyProperty SystemBackdropTypeProperty =
DependencyProperty.RegisterAttached(
"SystemBackdropType",
typeof(BackdropType),
typeof(WindowAttach),
new PropertyMetadata(BackdropType.Auto, OnSystemBackdropTypeChanged));

public static BackdropType GetSystemBackdropType(System.Windows.Window window)
{
return (BackdropType) window.GetValue(SystemBackdropTypeProperty);
}

public static void SetSystemBackdropType(System.Windows.Window window, BackdropType value)
{
window.SetValue(SystemBackdropTypeProperty, value);
}

private static void OnSystemBackdropTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is System.Windows.Window window)
{
window.Apply((BackdropType) e.NewValue);
}
}

#endregion
}
}
55 changes: 13 additions & 42 deletions src/Shared/HandyControl_Shared/HandyControls/Controls/Window!.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
using System.Windows.Media;
using HandyControl.Data;
using HandyControl.Tools;
#if NET40
using Microsoft.Windows.Shell;
#else
using System.Windows.Shell;
#endif
namespace HandyControl.Controls;

public partial class Window
Expand All @@ -24,53 +19,29 @@ public bool ExtendViewIntoNonClientArea

#region Mica

public static readonly DependencyProperty ApplyBackdropMaterialProperty = DependencyProperty.Register(
"ApplyBackdropMaterial", typeof(bool), typeof(Window),
new PropertyMetadata(ValueBoxes.FalseBox, OnApplyBackdropMaterialChanged));
public static readonly DependencyProperty SystemBackdropTypeProperty = DependencyProperty.Register(
"SystemBackdropType", typeof(BackdropType), typeof(Window),
new PropertyMetadata(BackdropType.Auto, OnSystemBackdropTypeChanged));

public bool ApplyBackdropMaterial
public BackdropType SystemBackdropType
{
get => (bool) GetValue(ApplyBackdropMaterialProperty);
set => SetValue(ApplyBackdropMaterialProperty, ValueBoxes.BooleanBox(value));
get => (BackdropType) GetValue(SystemBackdropTypeProperty);
set => SetValue(SystemBackdropTypeProperty, (BackdropType) value);
}

private static void OnApplyBackdropMaterialChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnSystemBackdropTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (Window) d;
ctl.InitMica();
ctl.InitMica((Window) d, (BackdropType) e.NewValue);
}

private void InitMica()
private void InitMica(Window window, BackdropType backdropType)
{
if (ApplyBackdropMaterial && OSVersionHelper.IsWindows11_OrGreater)
{
#if NET40
var chrome = new WindowChrome
{
CornerRadius = new CornerRadius(),
GlassFrameThickness = new Thickness(-1),
ResizeBorderThickness = new Thickness(8)
};
#else
var chrome = new WindowChrome
{
CornerRadius = new CornerRadius(),
ResizeBorderThickness = new Thickness(8),
GlassFrameThickness = new Thickness(-1),
NonClientFrameEdges = NonClientFrameEdges.None,
UseAeroCaptionButtons = false
};
#endif
WindowChrome.SetWindowChrome(this, chrome);
NonClientAreaBackground = Brushes.Transparent;
MicaHelper.ApplyMicaEffect(this);
}
else
{
MicaHelper.RemoveMicaEffect();
}
NonClientAreaBackground = Brushes.Transparent;
Background = Brushes.Transparent;
window.Apply(backdropType);
}

#endregion

#region Show/Hide NonClientArea Buttons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceCha
_currenTheme = changedTheme;
_currentAccent = changedAccent;

if (UsingSystemTheme || MicaHelper.IsMicaEffectApplied)
if (UsingSystemTheme)
{
ApplicationTheme = changedTheme;
AccentColor = changedAccent;
Expand Down
Loading