using System; using System.Windows; using System.Windows.Data; namespace Kingo.Plugin.NYYP { sealed class DependencyVariable : DependencyObject { static readonly DependencyProperty valueProperty = DependencyProperty.Register( "Value", typeof(T), typeof(DependencyVariable) ); public static DependencyProperty ValueProperty { get { return valueProperty; } } public T Value { get { return (T)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public void SetBinding(Binding binding) { BindingOperations.SetBinding(this, ValueProperty, binding); } public void SetBinding(object dataContext, string propertyPath) { SetBinding(new Binding(propertyPath) { Source = dataContext }); } } }