【发布时间】:2017-07-10 22:50:09
【问题描述】:
在 Silverlight 中,我使用 MVVM 为相关的 ViewModel 定义了一个基类,并为在多个子类中定义的属性定义了一个可能值列表:
namespace MyNameSpace
{
public class MyViewModelBase
{
public static List<MyPropertyClass> MyPropertyValueList
{
get
{
if (myPropertyValueList == null)
{
// fill the list
}
return myPropertyValueList;
}
}
private static List<MyPropertyClass> myPropertyValueList = null;
}
}
现在我定义我的 ViewModel:
namespace MyNameSpace.MyChild
{
public class MyViewModelChild
{
public MyPropertyClass MyProperty
{
get
{
return myProperty;
}
set
{
myProperty= value;
RaisePropertyChanged("MyProperty");
}
}
...
}
}
我绑定到我的 ViewModel
<controls:ChildWindow
x:Class="MyNameSpace.MyChild.MyChildEditor">
<ListBox ItemsSource="{Binding Path=MyPropertyValueList, Mode=OneTime}" SelectedValue="{Binding Path=MyProperty, Mode=TwoWay}"/>
那么MyPropertyValueList 的绑定失败。
但是如果在子类中定义了MyPropertyValueList,它就可以工作。我做错了什么?
【问题讨论】:
标签: silverlight mvvm data-binding