123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System.ComponentModel;
- using System.Windows;
- namespace OpenSEMI.ClientBase.Command
- {
- public class PropertyCommandTrigger : CommandTrigger
- {
- public static readonly DependencyProperty PropertyProperty = DependencyProperty.Register("Property", typeof(DependencyProperty), typeof(PropertyCommandTrigger), new FrameworkPropertyMetadata(null));
- public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(PropertyCommandTrigger), new FrameworkPropertyMetadata(null));
- public static readonly DependencyProperty TProperty = DependencyProperty.Register("T", typeof(object), typeof(PropertyCommandTrigger), new FrameworkPropertyMetadata(null, OnTChanged));
- public DependencyProperty Property
- {
- get
- {
- return (DependencyProperty)GetValue(PropertyProperty);
- }
- set
- {
- SetValue(PropertyProperty, value);
- }
- }
- public string Value
- {
- get
- {
- return (string)GetValue(ValueProperty);
- }
- set
- {
- SetValue(ValueProperty, value);
- }
- }
- public object T
- {
- get
- {
- return GetValue(TProperty);
- }
- set
- {
- SetValue(TProperty, value);
- }
- }
- protected override Freezable CreateInstanceCore()
- {
- return new PropertyCommandTrigger();
- }
- private static void OnTChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- }
- protected override void InitializeCore(FrameworkElement source)
- {
- DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty(Property, source.GetType());
- descriptor.AddValueChanged(source, delegate
- {
- CommandParameter<object> parameter = new PropertyCommandParameter<object, object>(base.CustomParameter, Property, source.GetValue(Property));
- object objB = Value;
- if (descriptor.Converter.CanConvertFrom(typeof(string)))
- {
- objB = descriptor.Converter.ConvertFromString(Value);
- }
- if (object.Equals(source.GetValue(Property), objB))
- {
- ExecuteCommand(parameter);
- }
- });
- }
- }
- }
|