在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
它就可以了。我做错了什么?
答案 0 :(得分:1)
您将MyPropertyValueList
定义为 static 属性。它不允许在Silverlight中使用。