tôi xác định tài sản trong usercontrol của tôi như thế này:DependencyProperty không được kích hoạt
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set
{
SetValue(IsSelectedProperty, value);
StackPanelDetails.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
}
}
public static readonly DependencyProperty IsSelectedProperty =
DependencyProperty.Register("IsSelected", typeof (bool), typeof (ucMyControl));
Nhưng khi tôi đặt tài sản của mình trong XAML, nó muốn kích hoạt nó (thiết lập không được gọi).
<DataTemplate><local:ucTopicItem IsSelected="False" /></DataTemplate>
Điều gì có thể là vấn đề?
Lớp ucMyControl có chứa tập hợp các đối tượng ucTopicItem không? Chúng giống nhau hả? Bạn đang đăng ký DP trên ucMyControl, nhưng thiết lập nó trên một ucTopicItem. Bạn cũng có thể muốn thử RegisterAttached thay vì Register. – avanek