add Recommendation
This commit is contained in:
1 parent
ee4125e2bf
commit
cf5f84869d
33 files changed
+320
-141
No files matched your search
@@ -1,47 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using HandyControl.Interactivity;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class LinkElement
|
||||
{
|
||||
public static readonly DependencyProperty LinkProperty = DependencyProperty.RegisterAttached(
|
||||
"Link", typeof(string), typeof(LinkElement), new PropertyMetadata(default(string), OnLinkChanged));
|
||||
|
||||
private static void OnLinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is UIElement element)
|
||||
{
|
||||
CreateTrigger(element, (string) e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty CommandBindingProperty = DependencyProperty.RegisterAttached(
|
||||
"CommandBinding", typeof(CommandBinding), typeof(LinkElement), new PropertyMetadata(default(CommandBinding)));
|
||||
|
||||
private static void SetCommandBinding(DependencyObject element, CommandBinding value)
|
||||
=> element.SetValue(CommandBindingProperty, value);
|
||||
|
||||
private static CommandBinding GetCommandBinding(DependencyObject element)
|
||||
=> (CommandBinding) element.GetValue(CommandBindingProperty);
|
||||
|
||||
private static void CreateTrigger(UIElement element, string link)
|
||||
{
|
||||
element.CommandBindings.Remove(GetCommandBinding(element));
|
||||
element.SetCurrentValue(CommandBindingProperty, DependencyProperty.UnsetValue);
|
||||
|
||||
if (string.IsNullOrEmpty(link)) return;
|
||||
var commandBinding = new CommandBinding(ControlCommands.OpenLink, (sender, args) => Process.Start(link));
|
||||
SetCommandBinding(element, commandBinding);
|
||||
element.CommandBindings.Add(commandBinding);
|
||||
}
|
||||
|
||||
public static void SetLink(DependencyObject element, string value)
|
||||
=> element.SetValue(LinkProperty, value);
|
||||
|
||||
public static string GetLink(DependencyObject element)
|
||||
=> (string) element.GetValue(LinkProperty);
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconSwitchElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\InfoElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\LinkElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PanelElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PasswordBoxMonitor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\GlobalShortcut.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\StatusSwitchElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\TipElement.cs" />
|
||||
@@ -182,7 +182,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\BehaviorCollection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\ControlCommands.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\ControlCommands.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\DefaultTriggerAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\EventToCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\EventTrigger.cs" />
|
||||
@@ -201,9 +201,9 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\NameResolvedEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\NameResolver.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\PreviewInvokeEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\PushMainWindow2TopCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\PushMainWindow2TopCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\RoutedEventTrigger.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\ShutdownAppCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\ShutdownAppCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\TagType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\TransitionEffect.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\TriggerAction!1.cs" />
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ namespace HandyControl.Interactivity
|
||||
/// <summary>
|
||||
/// 打开链接
|
||||
/// </summary>
|
||||
public static RoutedCommand OpenLink { get; } = new RoutedCommand(nameof(OpenLink), typeof(ControlCommands));
|
||||
public static OpenLinkCommand OpenLink { get; } = new OpenLinkCommand();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭程序
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace HandyControl.Interactivity
|
||||
{
|
||||
public class OpenLinkCommand : ICommand
|
||||
{
|
||||
public bool CanExecute(object parameter) => true;
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
if (parameter is string link)
|
||||
{
|
||||
Process.Start(link);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user