update to v1.3.0
This commit is contained in:
1 parent
a68b0213a6
commit
9daa1a6ee1
60 files changed
+2391
-76
No files matched your search
@@ -31,5 +31,40 @@ namespace HandyControl.Interactivity
|
||||
/// 下一个
|
||||
/// </summary>
|
||||
public static RoutedCommand Next { get; } = new RoutedCommand("Next", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 上午
|
||||
/// </summary>
|
||||
public static RoutedCommand Am { get; } = new RoutedCommand("Am", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 下午
|
||||
/// </summary>
|
||||
public static RoutedCommand Pm { get; } = new RoutedCommand("Pm", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 确认
|
||||
/// </summary>
|
||||
public static RoutedCommand Sure { get; } = new RoutedCommand("Sure", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 小时改变
|
||||
/// </summary>
|
||||
public static RoutedCommand HourChange { get; } = new RoutedCommand("HourChange", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 分钟改变
|
||||
/// </summary>
|
||||
public static RoutedCommand MinuteChange { get; } = new RoutedCommand("MinuteChange", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 秒改变
|
||||
/// </summary>
|
||||
public static RoutedCommand SecondChange { get; } = new RoutedCommand("SecondChange", typeof(ControlCommands));
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标移动
|
||||
/// </summary>
|
||||
public static RoutedCommand MouseMove { get; } = new RoutedCommand("MouseMove", typeof(ControlCommands));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*refrence from https://github.com/lbugnion/mvvmlight*/
|
||||
|
||||
//The MIT License(MIT)
|
||||
|
||||
//Copyright(c) 2009 - 2018 Laurent Bugnion
|
||||
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files (the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions:
|
||||
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace HandyControl.Interactivity
|
||||
{
|
||||
public class EventToCommand : TriggerAction<DependencyObject>
|
||||
{
|
||||
public const string EventArgsConverterParameterPropertyName = "EventArgsConverterParameter";
|
||||
|
||||
public const string AlwaysInvokeCommandPropertyName = "AlwaysInvokeCommand";
|
||||
|
||||
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
|
||||
nameof(CommandParameter), typeof(object), typeof(EventToCommand), new PropertyMetadata(null,
|
||||
(s, e) =>
|
||||
{
|
||||
var eventToCommand = s as EventToCommand;
|
||||
if (eventToCommand?.AssociatedObject == null)
|
||||
return;
|
||||
eventToCommand.EnableDisableElement();
|
||||
}));
|
||||
|
||||
public static readonly DependencyProperty CommandProperty =
|
||||
DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(EventToCommand),
|
||||
new PropertyMetadata(null, (s, e) => OnCommandChanged(s as EventToCommand, e)));
|
||||
|
||||
public static readonly DependencyProperty MustToggleIsEnabledProperty = DependencyProperty.Register(
|
||||
nameof(MustToggleIsEnabled), typeof(bool), typeof(EventToCommand), new PropertyMetadata(false,
|
||||
(s, e) =>
|
||||
{
|
||||
var eventToCommand = s as EventToCommand;
|
||||
if (eventToCommand?.AssociatedObject == null)
|
||||
return;
|
||||
eventToCommand.EnableDisableElement();
|
||||
}));
|
||||
|
||||
public static readonly DependencyProperty EventArgsConverterParameterProperty =
|
||||
DependencyProperty.Register(nameof(EventArgsConverterParameter), typeof(object),
|
||||
typeof(EventToCommand), new PropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty AlwaysInvokeCommandProperty =
|
||||
DependencyProperty.Register(nameof(AlwaysInvokeCommand), typeof(bool), typeof(EventToCommand),
|
||||
new PropertyMetadata(false));
|
||||
|
||||
private object _commandParameterValue;
|
||||
|
||||
private bool? _mustToggleValue;
|
||||
|
||||
public ICommand Command
|
||||
{
|
||||
get => (ICommand) GetValue(CommandProperty);
|
||||
set => SetValue(CommandProperty, value);
|
||||
}
|
||||
|
||||
public object CommandParameter
|
||||
{
|
||||
get => GetValue(CommandParameterProperty);
|
||||
set => SetValue(CommandParameterProperty, value);
|
||||
}
|
||||
|
||||
public object CommandParameterValue
|
||||
{
|
||||
get => _commandParameterValue ?? CommandParameter;
|
||||
set
|
||||
{
|
||||
_commandParameterValue = value;
|
||||
EnableDisableElement();
|
||||
}
|
||||
}
|
||||
|
||||
public bool MustToggleIsEnabled
|
||||
{
|
||||
get => (bool) GetValue(MustToggleIsEnabledProperty);
|
||||
set => SetValue(MustToggleIsEnabledProperty, value);
|
||||
}
|
||||
|
||||
public bool MustToggleIsEnabledValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mustToggleValue.HasValue)
|
||||
return _mustToggleValue.Value;
|
||||
return MustToggleIsEnabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
_mustToggleValue = value;
|
||||
EnableDisableElement();
|
||||
}
|
||||
}
|
||||
|
||||
public bool PassEventArgsToCommand { get; set; }
|
||||
|
||||
public IEventArgsConverter EventArgsConverter { get; set; }
|
||||
|
||||
public object EventArgsConverterParameter
|
||||
{
|
||||
get => GetValue(EventArgsConverterParameterProperty);
|
||||
set => SetValue(EventArgsConverterParameterProperty, value);
|
||||
}
|
||||
|
||||
public bool AlwaysInvokeCommand
|
||||
{
|
||||
get => (bool) GetValue(AlwaysInvokeCommandProperty);
|
||||
set => SetValue(AlwaysInvokeCommandProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
EnableDisableElement();
|
||||
}
|
||||
|
||||
private FrameworkElement GetAssociatedObject() => AssociatedObject as FrameworkElement;
|
||||
|
||||
private ICommand GetCommand() => Command;
|
||||
|
||||
public void Invoke() => Invoke(null);
|
||||
|
||||
protected override void Invoke(object parameter)
|
||||
{
|
||||
if (AssociatedElementIsDisabled() && !AlwaysInvokeCommand)
|
||||
return;
|
||||
var command = GetCommand();
|
||||
var parameter1 = CommandParameterValue;
|
||||
if (parameter1 == null && PassEventArgsToCommand)
|
||||
parameter1 = EventArgsConverter == null
|
||||
? parameter
|
||||
: EventArgsConverter.Convert(parameter, EventArgsConverterParameter);
|
||||
if (command == null || !command.CanExecute(parameter1))
|
||||
return;
|
||||
command.Execute(parameter1);
|
||||
}
|
||||
|
||||
private static void OnCommandChanged(EventToCommand element, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (element == null)
|
||||
return;
|
||||
if (e.OldValue != null)
|
||||
((ICommand) e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
|
||||
var newValue = (ICommand) e.NewValue;
|
||||
if (newValue != null)
|
||||
newValue.CanExecuteChanged += element.OnCommandCanExecuteChanged;
|
||||
element.EnableDisableElement();
|
||||
}
|
||||
|
||||
private bool AssociatedElementIsDisabled()
|
||||
{
|
||||
var associatedObject = GetAssociatedObject();
|
||||
if (AssociatedObject == null)
|
||||
return true;
|
||||
if (associatedObject != null)
|
||||
return !associatedObject.IsEnabled;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void EnableDisableElement()
|
||||
{
|
||||
var associatedObject = GetAssociatedObject();
|
||||
if (associatedObject == null)
|
||||
return;
|
||||
var command = GetCommand();
|
||||
if (!MustToggleIsEnabledValue || command == null)
|
||||
return;
|
||||
associatedObject.IsEnabled = command.CanExecute(CommandParameterValue);
|
||||
}
|
||||
|
||||
private void OnCommandCanExecuteChanged(object sender, EventArgs e) => EnableDisableElement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*refrence from https://github.com/lbugnion/mvvmlight*/
|
||||
|
||||
//The MIT License(MIT)
|
||||
|
||||
//Copyright(c) 2009 - 2018 Laurent Bugnion
|
||||
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files (the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions:
|
||||
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
namespace HandyControl.Interactivity
|
||||
{
|
||||
public interface IEventArgsConverter
|
||||
{
|
||||
object Convert(object value, object parameter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace HandyControl.Interactivity
|
||||
{
|
||||
public class RoutedEventTrigger : EventTriggerBase<DependencyObject>
|
||||
{
|
||||
public RoutedEvent RoutedEvent { get; set; }
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
var behavior = AssociatedObject as Behavior;
|
||||
var associatedElement = AssociatedObject as FrameworkElement;
|
||||
if (behavior != null) associatedElement = ((IAttachedObject)behavior).AssociatedObject as FrameworkElement;
|
||||
if (associatedElement == null) throw new ArgumentException();
|
||||
if (RoutedEvent != null) associatedElement.AddHandler(RoutedEvent, new RoutedEventHandler(OnRoutedEvent));
|
||||
}
|
||||
|
||||
private void OnRoutedEvent(object sender, RoutedEventArgs args)
|
||||
{
|
||||
OnEvent(args);
|
||||
}
|
||||
|
||||
protected override string GetEventName()
|
||||
{
|
||||
return RoutedEvent.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user