【发布时间】:2010-12-10 19:50:18
【问题描述】:
“PropertyChanged”事件是否让 View 在使用它的模型的生命周期内保持活跃?
例如,这段代码是否不会在视图模型的生命周期内保持视图处于活动状态?
public MyView(MyViewModel a_viewModel)
{
Loaded += (s, e) =>
{
DataContext = a_viewModel;
};
}
好的,不好的例子。这是我在ViewModelBase 课程中真正担心的代码:
protected void RelayPropertyChanges(INotifyPropertyChanged a_source, String a_strSourceProperty, String a_strTargetProperty)
{
ValidatePropertyExists(a_strTargetProperty);
if (a_source is ViewModelBase)
(a_source as ViewModelBase).ValidatePropertyExists(a_strSourceProperty);
a_source.PropertyChanged += (s, e) => OnPropertyChanged(a_strTargetProperty);
}
而且,我刚刚意识到这行不通。我会在这件事上回复你们;对如何实现这项工作有任何想法?
【问题讨论】:
-
活着的意思是没有被GC'ed?
-
是的(但“是的”是短评论。)
标签: wpf binding inotifypropertychanged