Commit ee80935a authored by 潘栩锋's avatar 潘栩锋 🚴

ParamDictionary 添加绑定功能

parent 489fb855
......@@ -133,12 +133,26 @@ namespace Misc
/// <param name="propertyName"></param>
/// <param name="defaultValue"></param>
public void SetBinding<T>(INotifyPropertyChanged target, string propertyName, T defaultValue)
{
SetBinding<T>(target, propertyName, propertyName, defaultValue);
}
/// <summary>
/// 双向绑定
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="target"></param>
/// <param name="propertyName"></param>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
public void SetBinding<T>(INotifyPropertyChanged target, string propertyName, string key, T defaultValue)
{
Type type_s = target.GetType();
System.Reflection.PropertyInfo pi_t = type_s.GetProperty(propertyName);
if (pi_t == null)
return;
object obj = GetValue<T>(propertyName, defaultValue);
object obj = this.GetValue<T>(key, defaultValue);
pi_t.SetValue(target, obj);
target.PropertyChanged += (s, e) =>
......@@ -146,19 +160,19 @@ namespace Misc
if (e.PropertyName == propertyName)
{
object o = pi_t.GetValue(target);
SetValue(propertyName, o);
this.SetValue(key, o);
}
};
ValueChanged += (s, e) =>
{
if (e.Key == propertyName) {
object o = GetValue<T>(propertyName, defaultValue);
pi_t.SetValue(target, o);
if (e.Key == key)
{
pi_t.SetValue(target, e.Value);
}
};
}
private string path;
public event UiParamDictionaryValueChangedHandler ValueChanged;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment