This commit is contained in:
NaBian committed 2019-09-18 21:49:37 +08:00
1 parent 846ab427ef
commit 6e1d294202
6 files changed
+97 -26

No files matched your search

@@ -18,17 +18,17 @@
<hc:SideMenuItem.Icon> <hc:SideMenuItem.Icon>
<Image Source="/HandyControlDemo;component/Resources/Img/DevOps/DevOps-Overview.png" Width="24" Height="24"/> <Image Source="/HandyControlDemo;component/Resources/Img/DevOps/DevOps-Overview.png" Width="24" Height="24"/>
</hc:SideMenuItem.Icon> </hc:SideMenuItem.Icon>
<hc:SideMenuItem Header="Summary"> <hc:SideMenuItem Header="Summary" Command="{Binding SelectCmd}" CommandParameter="{Binding Header,RelativeSource={RelativeSource Self}}">
<hc:SideMenuItem.Icon> <hc:SideMenuItem.Icon>
<TextBlock Text="&#xf2cb;" Style="{StaticResource TextBlockFabricIcons}"/> <TextBlock Text="&#xf2cb;" Style="{StaticResource TextBlockFabricIcons}"/>
</hc:SideMenuItem.Icon> </hc:SideMenuItem.Icon>
</hc:SideMenuItem> </hc:SideMenuItem>
<hc:SideMenuItem Header="Dashboards"> <hc:SideMenuItem Header="Dashboards" Command="{Binding SelectCmd}" CommandParameter="{Binding Header,RelativeSource={RelativeSource Self}}">
<hc:SideMenuItem.Icon> <hc:SideMenuItem.Icon>
<TextBlock Text="&#xf246;" Style="{StaticResource TextBlockFabricIcons}"/> <TextBlock Text="&#xf246;" Style="{StaticResource TextBlockFabricIcons}"/>
</hc:SideMenuItem.Icon> </hc:SideMenuItem.Icon>
</hc:SideMenuItem> </hc:SideMenuItem>
<hc:SideMenuItem Header="Wiki"> <hc:SideMenuItem Header="Wiki" Command="{Binding SelectCmd}" CommandParameter="{Binding Header,RelativeSource={RelativeSource Self}}">
<hc:SideMenuItem.Icon> <hc:SideMenuItem.Icon>
<TextBlock Text="&#xe82d;" Style="{StaticResource TextBlockFabricIcons}"/> <TextBlock Text="&#xe82d;" Style="{StaticResource TextBlockFabricIcons}"/>
</hc:SideMenuItem.Icon> </hc:SideMenuItem.Icon>
@@ -16,5 +16,10 @@ namespace HandyControlDemo.ViewModel
new RelayCommand<FunctionEventArgs<object>>(SwitchItem)).Value; new RelayCommand<FunctionEventArgs<object>>(SwitchItem)).Value;
private void SwitchItem(FunctionEventArgs<object> info) => Growl.Info((info.Info as SideMenuItem)?.Header.ToString()); private void SwitchItem(FunctionEventArgs<object> info) => Growl.Info((info.Info as SideMenuItem)?.Header.ToString());
public RelayCommand<string> SelectCmd => new Lazy<RelayCommand<string>>(() =>
new RelayCommand<string>(Select)).Value;
private void Select(string header) => Growl.Success(header);
} }
} }
@@ -52,14 +52,16 @@ namespace HandyControl.Controls
Info = Text Info = Text
}); });
if (Command == null) return; switch (Command)
if (Command is RoutedCommand command)
{ {
command.Execute(CommandParameter, CommandTarget); case null:
} return;
else case RoutedCommand command:
{ command.Execute(CommandParameter, CommandTarget);
Command.Execute(CommandParameter); break;
default:
Command.Execute(CommandParameter);
break;
} }
} }
@@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
@@ -7,7 +8,7 @@ using HandyControl.Tools.Extension;
namespace HandyControl.Controls namespace HandyControl.Controls
{ {
public class SideMenuItem : HeaderedSimpleItemsControl, ISelectable public class SideMenuItem : HeaderedSimpleItemsControl, ISelectable, ICommandSource
{ {
private bool _isMouseLeftButtonDown; private bool _isMouseLeftButtonDown;
@@ -68,7 +69,22 @@ namespace HandyControl.Controls
} }
} }
protected virtual void OnSelected(RoutedEventArgs e) => RaiseEvent(e); protected virtual void OnSelected(RoutedEventArgs e)
{
RaiseEvent(e);
switch (Command)
{
case null:
return;
case RoutedCommand command:
command.Execute(CommandParameter, CommandTarget);
break;
default:
Command.Execute(CommandParameter);
break;
}
}
public static readonly RoutedEvent SelectedEvent = public static readonly RoutedEvent SelectedEvent =
EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble, EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble,
@@ -148,5 +164,54 @@ namespace HandyControl.Controls
ItemsHost.Show(isShow); ItemsHost.Show(isShow);
} }
} }
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command", typeof(ICommand), typeof(SideMenuItem), new PropertyMetadata(default(ICommand), OnCommandChanged));
private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (SideMenuItem)d;
if (e.OldValue is ICommand oldCommand)
{
oldCommand.CanExecuteChanged -= ctl.CanExecuteChanged;
}
if (e.NewValue is ICommand newCommand)
{
newCommand.CanExecuteChanged += ctl.CanExecuteChanged;
}
}
public ICommand Command
{
get => (ICommand) GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
"CommandParameter", typeof(object), typeof(SideMenuItem), new PropertyMetadata(default(object)));
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register(
"CommandTarget", typeof(IInputElement), typeof(SideMenuItem), new PropertyMetadata(default(IInputElement)));
public IInputElement CommandTarget
{
get => (IInputElement) GetValue(CommandTargetProperty);
set => SetValue(CommandTargetProperty, value);
}
private void CanExecuteChanged(object sender, EventArgs e)
{
if (Command == null) return;
IsEnabled = Command is RoutedCommand command
? command.CanExecute(CommandParameter, CommandTarget)
: Command.CanExecute(CommandParameter);
}
} }
} }
@@ -1,5 +1,4 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using HandyControl.Data; using HandyControl.Data;
using HandyControl.Tools; using HandyControl.Tools;
@@ -18,18 +17,8 @@ namespace HandyControl.Controls
internal static void EnableBlur(Window window) internal static void EnableBlur(Window window)
{ {
var accentPolicy = new ExternDllHelper.ACCENTPOLICY(); if (SystemVersionInfo < SystemVersionInfo.Windows10 ||
var accentPolicySize = Marshal.SizeOf(accentPolicy); SystemVersionInfo >= SystemVersionInfo.Windows10_1903)
if (SystemVersionInfo >= SystemVersionInfo.Windows10_1809)
{
accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND;
}
else if (SystemVersionInfo >= SystemVersionInfo.Windows10)
{
accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND;
}
else
{ {
var colorValue = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue); var colorValue = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue);
var color = ColorHelper.ToColor(colorValue); var color = ColorHelper.ToColor(colorValue);
@@ -38,6 +27,13 @@ namespace HandyControl.Controls
return; return;
} }
var accentPolicy = new ExternDllHelper.ACCENTPOLICY();
var accentPolicySize = Marshal.SizeOf(accentPolicy);
accentPolicy.AccentState = SystemVersionInfo < SystemVersionInfo.Windows10_1809
? ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND
: ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND;
accentPolicy.AccentFlags = 2; accentPolicy.AccentFlags = 2;
accentPolicy.GradientColor = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue); accentPolicy.GradientColor = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue);
@@ -8,8 +8,11 @@ namespace HandyControl.Data
public struct SystemVersionInfo public struct SystemVersionInfo
{ {
public static SystemVersionInfo Windows10 => new SystemVersionInfo(10, 0, 10240); public static SystemVersionInfo Windows10 => new SystemVersionInfo(10, 0, 10240);
public static SystemVersionInfo Windows10_1809 => new SystemVersionInfo(10, 0, 17763); public static SystemVersionInfo Windows10_1809 => new SystemVersionInfo(10, 0, 17763);
public static SystemVersionInfo Windows10_1903 => new SystemVersionInfo(10, 0, 18362);
public SystemVersionInfo(int major, int minor, int build) public SystemVersionInfo(int major, int minor, int build)
{ {
Major = major; Major = major;