diff --git a/HandyControl/Controls/Attach/IconElement.cs b/HandyControl/Controls/Attach/IconElement.cs index 9a39bbc1..04fc803b 100644 --- a/HandyControl/Controls/Attach/IconElement.cs +++ b/HandyControl/Controls/Attach/IconElement.cs @@ -16,7 +16,7 @@ namespace HandyControl.Controls => (Geometry) element.GetValue(GeometryProperty); public static readonly DependencyProperty WidthProperty = DependencyProperty.RegisterAttached( - "Width", typeof(double), typeof(IconElement), new PropertyMetadata(ValueBoxes.Double0Box)); + "Width", typeof(double), typeof(IconElement), new PropertyMetadata(double.NaN)); public static void SetWidth(DependencyObject element, double value) => element.SetValue(WidthProperty, value); @@ -25,7 +25,7 @@ namespace HandyControl.Controls => (double) element.GetValue(WidthProperty); public static readonly DependencyProperty HeightProperty = DependencyProperty.RegisterAttached( - "Height", typeof(double), typeof(IconElement), new PropertyMetadata(ValueBoxes.Double0Box)); + "Height", typeof(double), typeof(IconElement), new PropertyMetadata(double.NaN)); public static void SetHeight(DependencyObject element, double value) => element.SetValue(HeightProperty, value); diff --git a/HandyControl/Controls/Attach/IconSwitchElement.cs b/HandyControl/Controls/Attach/IconSwitchElement.cs index 8bdcfb2d..714b2036 100644 --- a/HandyControl/Controls/Attach/IconSwitchElement.cs +++ b/HandyControl/Controls/Attach/IconSwitchElement.cs @@ -3,21 +3,8 @@ using System.Windows.Media; namespace HandyControl.Controls { - public class IconSwitchElement + public class IconSwitchElement : IconElement { - public static readonly DependencyProperty GeometryProperty = DependencyProperty.RegisterAttached( - "Geometry", typeof(Geometry), typeof(IconSwitchElement), new PropertyMetadata(default(Geometry))); - - public static void SetGeometry(DependencyObject element, Geometry value) - { - element.SetValue(GeometryProperty, value); - } - - public static Geometry GetGeometry(DependencyObject element) - { - return (Geometry)element.GetValue(GeometryProperty); - } - public static readonly DependencyProperty GeometrySelectedProperty = DependencyProperty.RegisterAttached( "GeometrySelected", typeof(Geometry), typeof(IconSwitchElement), new PropertyMetadata(default(Geometry))); diff --git a/HandyControl/Controls/Other/ColorPicker.cs b/HandyControl/Controls/Other/ColorPicker.cs index 648dc3c6..96e2020d 100644 --- a/HandyControl/Controls/Other/ColorPicker.cs +++ b/HandyControl/Controls/Other/ColorPicker.cs @@ -675,7 +675,7 @@ namespace HandyControl.Controls private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) => RaiseEvent(new RoutedEventArgs(CanceledEvent)); - public void Dispose() => Window.GetWindow(this)?.Close(); + public void Dispose() => System.Windows.Window.GetWindow(this)?.Close(); public bool CanDispose { get; } = true; } diff --git a/HandyControl/Controls/Window/BlurWindow.cs b/HandyControl/Controls/Window/BlurWindow.cs new file mode 100644 index 00000000..44ec09d5 --- /dev/null +++ b/HandyControl/Controls/Window/BlurWindow.cs @@ -0,0 +1,53 @@ +using System.Runtime.InteropServices; +using System.Windows.Interop; +using HandyControl.Data; +using HandyControl.Tools; + +namespace HandyControl.Controls +{ + public class BlurWindow : Window + { + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + EnableBlur(this); + } + + internal static void EnableBlur(Window window) + { + var accentPolicy = new ExternDllHelper.ACCENTPOLICY(); + var accentPolicySize = Marshal.SizeOf(accentPolicy); + var versionInfo = CommonHelper.GetSystemVersionInfo(); + + if (versionInfo >= SystemVersionInfo.Windows10_1809) + { + accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND; + } + else if (versionInfo >= SystemVersionInfo.Windows10) + { + accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND; + } + else + { + accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_TRANSPARENTGRADIENT; + } + + accentPolicy.AccentFlags = 2; + accentPolicy.GradientColor = ResourceHelper.GetResource("BlurGradientValue"); + + var accentPtr = Marshal.AllocHGlobal(accentPolicySize); + Marshal.StructureToPtr(accentPolicy, accentPtr, false); + + var data = new ExternDllHelper.WINCOMPATTRDATA + { + Attribute = ExternDllHelper.WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY, + DataSize = accentPolicySize, + Data = accentPtr + }; + + ExternDllHelper.SetWindowCompositionAttribute(new WindowInteropHelper(window).Handle, ref data); + + Marshal.FreeHGlobal(accentPtr); + } + } +} \ No newline at end of file diff --git a/HandyControl/Controls/Window/ImageBrowser.cs b/HandyControl/Controls/Window/ImageBrowser.cs index e74d9922..f5af1a8d 100644 --- a/HandyControl/Controls/Window/ImageBrowser.cs +++ b/HandyControl/Controls/Window/ImageBrowser.cs @@ -14,7 +14,7 @@ namespace HandyControl.Controls /// [TemplatePart(Name = ElementGridTop, Type = typeof(Grid))] [TemplatePart(Name = ElementImageViewer, Type = typeof(ImageViewer))] - public class ImageBrowser : WindowBorderless + public class ImageBrowser : Window { #region Constants diff --git a/HandyControl/Controls/Window/PopupWindow.cs b/HandyControl/Controls/Window/PopupWindow.cs index 833b75fe..f28418b9 100644 --- a/HandyControl/Controls/Window/PopupWindow.cs +++ b/HandyControl/Controls/Window/PopupWindow.cs @@ -15,7 +15,7 @@ namespace HandyControl.Controls /// [TemplatePart(Name = ElementMainBorder, Type = typeof(Border))] [TemplatePart(Name = ElementTitleBlock, Type = typeof(TextBlock))] - public class PopupWindow : Window + public class PopupWindow : System.Windows.Window { #region Constants @@ -98,7 +98,7 @@ namespace HandyControl.Controls } } - public PopupWindow(Window owner) : this() => Owner = owner; + public PopupWindow(System.Windows.Window owner) : this() => Owner = owner; private void CloseButton_OnClick(object sender, RoutedEventArgs e) => Close(); @@ -173,7 +173,7 @@ namespace HandyControl.Controls ShowDialog(); } - public void Show(Window element, Point point) + public void Show(System.Windows.Window element, Point point) { Left = element.Left + point.X; Top = element.Top + point.Y; diff --git a/HandyControl/Controls/Window/WindowBorderless.cs b/HandyControl/Controls/Window/Window.cs similarity index 91% rename from HandyControl/Controls/Window/WindowBorderless.cs rename to HandyControl/Controls/Window/Window.cs index f806468e..a4dc30a4 100644 --- a/HandyControl/Controls/Window/WindowBorderless.cs +++ b/HandyControl/Controls/Window/Window.cs @@ -14,71 +14,68 @@ using System.Windows.Shell; namespace HandyControl.Controls { - /// - /// 无边框窗口 - /// - public class WindowBorderless : Window + public class Window : System.Windows.Window { private Thickness _tempThickness; public static readonly DependencyProperty NonClientAreaContentProperty = DependencyProperty.Register( - "NonClientAreaContent", typeof(object), typeof(WindowBorderless), new PropertyMetadata(default(object))); + "NonClientAreaContent", typeof(object), typeof(Window), new PropertyMetadata(default(object))); public static readonly DependencyProperty CloseButtonHoverBackgroundProperty = DependencyProperty.Register( - "CloseButtonHoverBackground", typeof(Brush), typeof(WindowBorderless), + "CloseButtonHoverBackground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty CloseButtonHoverForegroundProperty = DependencyProperty.Register( - "CloseButtonHoverForeground", typeof(Brush), typeof(WindowBorderless), + "CloseButtonHoverForeground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty CloseButtonBackgroundProperty = DependencyProperty.Register( - "CloseButtonBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.Transparent)); + "CloseButtonBackground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.Transparent)); public static readonly DependencyProperty CloseButtonForegroundProperty = DependencyProperty.Register( - "CloseButtonForeground", typeof(Brush), typeof(WindowBorderless), + "CloseButtonForeground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.White)); public static readonly DependencyProperty OtherButtonBackgroundProperty = DependencyProperty.Register( - "OtherButtonBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.Transparent)); + "OtherButtonBackground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.Transparent)); public static readonly DependencyProperty OtherButtonForegroundProperty = DependencyProperty.Register( - "OtherButtonForeground", typeof(Brush), typeof(WindowBorderless), + "OtherButtonForeground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.White)); public static readonly DependencyProperty OtherButtonHoverBackgroundProperty = DependencyProperty.Register( - "OtherButtonHoverBackground", typeof(Brush), typeof(WindowBorderless), + "OtherButtonHoverBackground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty OtherButtonHoverForegroundProperty = DependencyProperty.Register( - "OtherButtonHoverForeground", typeof(Brush), typeof(WindowBorderless), + "OtherButtonHoverForeground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty NonClientAreaBackgroundProperty = DependencyProperty.Register( - "NonClientAreaBackground", typeof(Brush), typeof(WindowBorderless), + "NonClientAreaBackground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty NonClientAreaForegroundProperty = DependencyProperty.Register( - "NonClientAreaForeground", typeof(Brush), typeof(WindowBorderless), + "NonClientAreaForeground", typeof(Brush), typeof(Window), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty NonClientAreaHeightProperty = DependencyProperty.Register( - "NonClientAreaHeight", typeof(double), typeof(WindowBorderless), + "NonClientAreaHeight", typeof(double), typeof(Window), new PropertyMetadata(28.0)); public static readonly DependencyProperty ShowNonClientAreaProperty = DependencyProperty.Register( - "ShowNonClientArea", typeof(bool), typeof(WindowBorderless), new PropertyMetadata(ValueBoxes.TrueBox)); + "ShowNonClientArea", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.TrueBox)); public static readonly DependencyProperty ShowTitleProperty = DependencyProperty.Register( - "ShowTitle", typeof(bool), typeof(WindowBorderless), new PropertyMetadata(ValueBoxes.FalseBox)); + "ShowTitle", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.FalseBox)); public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register( - "IsFullScreen", typeof(bool), typeof(WindowBorderless), new PropertyMetadata(ValueBoxes.FalseBox, + "IsFullScreen", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.FalseBox, (o, args) => { - var ctl = (WindowBorderless)o; + var ctl = (Window)o; var v = (bool)args.NewValue; if (v) { @@ -99,7 +96,7 @@ namespace HandyControl.Controls } })); - public WindowBorderless() + public Window() { var chrome = new WindowChrome { @@ -277,11 +274,11 @@ namespace HandyControl.Controls /// 获取自定义窗口 /// /// - public static WindowBorderless GetCustomWindow(FrameworkElement content) + public static Window GetCustomWindow(FrameworkElement content) { - var window = new WindowBorderless + var window = new Window { - Style = ResourceHelper.GetResource - + + - + + - + + - + + + + diff --git a/HandyControlDemo/UserControl/Controls/WindowDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/WindowDemoCtl.xaml index d719209c..ae0ca350 100644 --- a/HandyControlDemo/UserControl/Controls/WindowDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/WindowDemoCtl.xaml @@ -9,6 +9,7 @@ - + - \ No newline at end of file + \ No newline at end of file diff --git a/README.md b/README.md index 5fd58e9c..3ca5cde8 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ ## Latest examples +### BlurWindow + +![BlurWindow](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/BlurWindow.png) + ### FlipClock ![FlipClock](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/FlipClock.gif) diff --git a/Resources/BlurWindow.png b/Resources/BlurWindow.png new file mode 100644 index 00000000..821cd44d Binary files /dev/null and b/Resources/BlurWindow.png differ