我可以绑定WinRT / Windows 8商店应用程序中的DynamicObject
我有以下代码:
public class MyClass: DynamicObject, INotifyPropertyChanged { Dictionary properties = new Dictionary(); public override bool TryGetMember(GetMemberBinder binder, out object result) { if (properties.ContainsKey(binder.Name)) { result = properties[binder.Name]; return true; } else { result = "Invalid Property!"; return false; } } public override bool TrySetMember(SetMemberBinder binder, object value) { properties[binder.Name] = value; this.OnPropertyChanged(binder.Name); return true; } public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { dynamic method = properties[binder.Name]; result = method(args[0].ToString(), args[1].ToString()); return true; } ///.... Rest of the class. }
当我从xaml绑定它时,TryGetMember中的调试点不是triggeret。 我错过了什么吗?
datacontext设置为
public ObservableCollection SearchResults {get;set;}
和
ICollection col = item.SearchResults; this.DefaultViewModel["Results"] = col; //this is the datacontext of the gridview
这是我用于动态绑定的解决方案。 绑定语法只需要包含[]:
public class DynamicLocalSettings : BindableBase { public object this[string name] { get { if (ApplicationData.Current.LocalSettings.Values.ContainsKey(name)) return ApplicationData.Current.LocalSettings.Values[name]; return null; } set { ApplicationData.Current.LocalSettings.Values[name] = value; OnPropertyChanged(name); } } }