update to v1.2.1

This commit is contained in:
NaBian committed 2018-09-11 12:00:52 +08:00
1 parent f9475c318c
commit be950fac36
75 files changed
+2810 -288

No files matched your search

@@ -0,0 +1,72 @@
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
namespace HandyControl.Interactivity
{
public sealed class InvokeCommandAction : TriggerAction<DependencyObject>
{
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(InvokeCommandAction), null);
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(InvokeCommandAction),
null);
private string _commandName;
public string CommandName
{
get
{
ReadPreamble();
return _commandName;
}
set
{
if (CommandName == value)
return;
WritePreamble();
_commandName = value;
WritePostscript();
}
}
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
protected override void Invoke(object parameter)
{
if (AssociatedObject == null)
return;
var command = ResolveCommand();
if (command == null || !command.CanExecute(CommandParameter))
return;
command.Execute(CommandParameter);
}
private ICommand ResolveCommand()
{
var command = (ICommand)null;
if (Command != null)
command = Command;
else if (AssociatedObject != null)
foreach (var property in AssociatedObject.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public))
if (typeof(ICommand).IsAssignableFrom(property.PropertyType) &&
string.Equals(property.Name, CommandName, StringComparison.Ordinal))
command = (ICommand)property.GetValue(AssociatedObject, null);
return command;
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Windows;
namespace HandyControl.Interactivity
{
public abstract class TriggerAction<T> : TriggerAction where T : DependencyObject
{
protected TriggerAction() : base(typeof(T))
{
}
#pragma warning disable 108,114
protected T AssociatedObject => (T)base.AssociatedObject;
#pragma warning restore 108,114
protected sealed override Type AssociatedObjectTypeConstraint =>
base.AssociatedObjectTypeConstraint;
}
}
+2 -2
View File
@@ -9,12 +9,12 @@ namespace HandyControl.Interactivity
[ContentProperty("Actions")]
public abstract class TriggerBase : Animatable, IAttachedObject
{
public static readonly DependencyProperty ActionsProperty = ActionsPropertyKey.DependencyProperty;
private static readonly DependencyPropertyKey ActionsPropertyKey =
DependencyProperty.RegisterReadOnly("Actions", typeof(TriggerActionCollection), typeof(TriggerBase),
new FrameworkPropertyMetadata());
public static readonly DependencyProperty ActionsProperty = ActionsPropertyKey.DependencyProperty;
private DependencyObject _associatedObject;
private readonly Type _associatedObjectTypeConstraint;