0
在Silverlight中定义的静态属性,使用MVVM我定义相关的ViewModels一个基类和几个子类中定义的可能值的属性列表:的Silverlight:绑定到一个父类中的视图模型
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");
}
}
...
}
}
我绑定到我的视图模型
<controls:ChildWindow
x:Class="MyNameSpace.MyChild.MyChildEditor">
<ListBox ItemsSource="{Binding Path=MyPropertyValueList, Mode=OneTime}" SelectedValue="{Binding Path=MyProperty, Mode=TwoWay}"/>
然后绑定失败MyPropertyValueList
。 但是,如果MyPropertyValueList
在它的子类中定义了它的作用。我究竟做错了什么 ?
谢谢,它工作,如果我删除静态关键字。但是,如果该属性是在子类中定义的,为什么它也可以工作(使用static关键字)? – user2223898