[英]Unable to set style-trigger property to custom dependency property
I got another problem while working with my usercontrol's xaml file -.-' 使用usercontrol的xaml文件-.-时遇到另一个问题
I tried to implement an IsChecked
property to my custom button in order to set a different background colour if the button is checked. 我尝试对自定义按钮实现
IsChecked
属性,以便在选中按钮时设置不同的背景色。
So I created a DependencyProperty
like this: 所以我创建了一个这样的
DependencyProperty
:
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(LeftMenuBtn));
public bool IsChecked
{
get { return (bool)GetValue(IsCheckedProperty); }
set { SetValue(IsCheckedProperty, value); }
}
Then I setup a new style trigger to handle this property: 然后,我设置一个新样式的触发器来处理此属性:
<Style x:Key="ButtonEnableStates" TargetType="{x:Type Grid}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="{DynamicResource CheckedStateGradient}" />
</Trigger>
</Style.Triggers>
</Style>
Expression Blend now underlines Property="IsChecked"
and says: Expression Blend现在强调了
Property="IsChecked"
并说:
The member "IsChecked" is not recognized or is not accessible.
How can I solve this problem? 我怎么解决这个问题?
好吧, Style
的TargetType
是Grid
并且该属性是为LeftMenuBtn
定义的,不会那样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.