我创建了一个带有依赖项属性(source)的UserControl(TableWithFilter.xaml)。 UserControl是一个表,其中包含不同项的source属性。我创建了XAML并通过XAML Binding设置了source属性。到目前为止一切都很好。
但是如果更改依赖项属性的值,则不会调用已定义的回调方法。因此我无法更新表格中的条目。有谁知道为什么不调用回调方法?
以下是“TableWithFilter”类中我的属性的定义:
Public Shared ReadOnly SourceProperty As DependencyProperty = _
DependencyProperty.Register("Source", GetType(List(Of TableViewItem)), GetType(TableWithFilter), _
New FrameworkPropertyMetadata(Nothing, New PropertyChangedCallback(AddressOf TableWithFilter.ChangeSource)))
和Callback方法:
Private Shared Sub ChangeSource(ByVal source As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim table As TableWithFilter = source
table.Source = e.NewValue
End Sub
这里是XAML:
<Border Grid.Row="1" Grid.Column="1" BorderBrush="{StaticResource ElementBorder}" BorderThickness="1">
<local:TableWithFilter x:Name="SearchResultTable" Source="{Binding Source={StaticResource contentFacade}, Path=ContentList}" />
</Border>
如果更改了属性“ContentList”,我会考虑调用TableWithFilder类中的“ChangeSource”方法。但这种情况并非如此。在我更改ContentList属性后,我提出以下事件:
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("ContentList"))
感谢任何想法。
答案 0 :(得分:1)
整个属性更改(即对指定集合的新引用)与列表本身更改内容之间存在差异。集合有自己的名为INotifyCollectionChanged
的更改通知界面。所以你需要做的是监听你现在拥有的属性更改,并在其中将INotifyCollectionChanged
事件自己挂钩到新的集合实例上,然后对它们做出响应。