2015-05-24 44 views
0

我有一个公共属性StaticFailingPinListItem作为新的ObservableCollection(Of MyClass)在我的主用户控件UserControl1中。WPF将列表框绑定到ObservableCollection(Of MyClass)

Public Class UserControl1 
    Public Property StaticFailingPinListItem As New ObservableCollection(Of MyClass) 

MyClass有两个属性 - PinName & ImageLocation。

Public Class MyClass 
    Implements INotifyPropertyChanged 
    Public Property PinName 
    Public Property ImageLocation 

如果我在运行时手动添加项目到集合,我将能够在我的列表框中查看PinName属性。但是,如果我稍后添加项目(例如:在单击按钮之后)它不起作用。

这是我的XAML:

ItemsSource="{Binding ElementName =data2, Path=StaticFailingPinListItem}" DisplayMemberPath="PinName" 

所以,问题是我怎么做一个代码隐藏数据绑定我的列表框填充了采集后?

回答

0

接口INotifyPropertyChanged必须由包含保税属性的类来实现。
你的情况,这一定是UserControl1

您需要实现该接口上UserControl1

Public Class UserControl1 
    Implements INotifyPropertyChanged 
Public Property StaticFailingPinListItem As New ObservableCollection(Of MyClass) 

添加内容时点击按钮后,那么控制将被约在收集

变化通知
相关问题