我是 WPF 的新手,我的应用程序中有一个用户控件,它具有列表类型的依赖属性。
在我的窗口中,我放置了那个用户控件并将这个 DP 绑定到我的视图列表的属性。
最终属性会发生变化,因此作为集合但它不会反映在用户控件上。
我的视图实现了 INotifyPropertyChanged 接口。
我的用户控件的 DP 不会引发属性更改的事件。
可能的原因是什么?
我的用户控件中我的依赖属性的代码
public List<ItemsResult> ItemsCollection
{
get { return (List<ItemsResult>)GetValue(ItemsCollectionProperty); }
set { SetValue(ItemsCollectionProperty, value); }
}
public static readonly DependencyProperty ItemsCollectionProperty =
DependencyProperty.Register("ItemsCollection", typeof(List<ItemsResult>), typeof(ListingUserControl)
, new FrameworkPropertyMetadata(null, ItemsCollectionChanged));
private static void ItemsCollectionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs)
{
var listingUserControl = (obj as ListingUserControl);
var itemsResult = (eventArgs.NewValue as List<ItemsResult>);
if (listingUserControl != null && itemsResult != null)
listingUserControl.CountLabelVisible = itemsResult.Count > 0;
}
在我看来绑定
<my:ListingUserControl ItemsCollection="{Binding Clients}" Title="Client" />