Tôi có một tài sản phụ thuộc (Danh sách string) trong một điều khiển người dùng trong lắp ráp dot net của tôi như sauphụ thuộc Danh sách sở hữu <string> trong UserControl
public partial class ItemSelectionUserControl : UserControl
{
public List<string> AvailableItems
{
get { return (List<string>)this.GetValue(AvailableItemsProperty); }
set { this.SetValue(AvailableItemsProperty, value); }
}
public static readonly DependencyProperty AvailableItemsProperty = DependencyProperty.Register(
"AvailableItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata{BindsTwoWayByDefault =true});
public ItemSelectionUserControl()
{
InitializeComponent();
}
}
Tôi cố gắng để sử dụng usercontrol này trong usercontrol khác trong một khác nhau lắp ráp như bên dưới
<UserControl
xmlns:ctrl="clr-namespace:HH.Windows.UserControls;assembly=HH.Windows.UserControls"
/>
// .....
<Grid>
<ctrl:ItemSelectionUserControl Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" AvailableItems="{Binding Path=CheckList}"/>
</Grid>
Tôi có thể thấy người truy cập CheckList được gọi, nhưng không đặt thuộc tính phụ thuộc "AvailableItems". Điểm ngắt trong tập hợp "AvailableItems" không bao giờ được gọi. Tôi đang làm gì sai?
Có thể các loại không khớp? Xem [ở đây] (http://bea.stollnitz.com/blog/?p=52) để biết thêm thông tin về cách gỡ lỗi các ràng buộc WPF. –