我有以下属性Temp2 :(我的UserControl实现INotifyPropertyChanged)
ObservableCollection<Person> _Temp2; public ObservableCollection<Person> Temp2 { get { return _Temp2; } set { _Temp2 = value; OnPropertyChanged("Temp2"); } } public event PropertyChangedEventHandler PropertyChanged = delegate { }; private void OnPropertyChanged(string propertyName) { PropertyChanged(this,new PropertyChangedEventArgs(propertyName)); }
我需要动态创建一个列表.我在XAML中有以下列表:
<ListView Name="listView1" DataContext="{Binding Temp2}" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"> <ListView.View> .... etc
现在我试图用c#创建相同的列表视图:
ListView listView1 = new ListView(); listView1.DataContext = Temp2; listView1.ItemsSource = Temp2; // new Binding(); // ????? how do I have to implement this line listView1.IsSynchronizedWithCurrentItem = true; //.. etc
当我使用C#填充列表视图时,列表视图不会被填充.我究竟做错了什么?