我有一个ListView,它将每个列表视图项绑定到一个具有List
的A类<Page
DataContext="{Binding MainViewModel , Source={StaticResource Locator}}"
>
<ListView ItemsSource="{Binding A.List}" >
<ListView.ItemTemplate>
....
</ListView.ItemTemplate>
</ListView>
</Page>
在我的ViewModel中,我有一个类'A',它有一个属性List
public class MainViewModel : ViewModelBase {
private A _a;
public A A {
get {
return _a;
}
}
}
public class A
{
private IList<IList> _lists;
IList<int> List {
get {
return _lists;
};
set {
_lists = value;
RaisePropertyChanged("List");
}
}
在set()方法中,只要设置了List,我就调用了'RaisePropertyChanged()'。 但是当我运行它时,ListView内容不会得到更新。 我应该提高RaisePropertyChanged(“List”)或RaisePropertyChanged(“A.List”)(就像我在我的xaml中放入{Binding A.List]一样?在我的例子中,我将List设置为List的另一个实例。 / p>
答案 0 :(得分:0)
试试看看它是否有效。
public class A : INotifyPropertyChanged
{
private IList<int> _lists;
IList<int> List {
get {
return _lists;
};
set {
_lists = value;
OnPropertyChanged("List");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}