【发布时间】:2012-03-02 00:36:21
【问题描述】:
我在我的用户控件中定义了这样的属性:
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));
但是当我在 xaml 中设置它的属性时,它想触发它(不调用 set)。
<DataTemplate><local:ucTopicItem IsSelected="False" /></DataTemplate>
可能是什么问题?
【问题讨论】:
-
类 ucMyControl 是否包含 ucTopicItem 对象的集合?或者他们是同一个东西?您在 ucMyControl 上注册 DP,但在 ucTopicItem 上设置它。您可能还想尝试 RegisterAttached 而不是 Register。