[英]WPF Image 'highlight' with DropShadowEffect can't bind color
I have created a UserControl called ImageButton , and I am using a DropShadowEffect on MouseOver to show the button as 'active'. 我创建了一个名为ImageButton的UserControl,并且在MouseOver上使用了DropShadowEffect将按钮显示为“活动”。 However, I cannot seem to bind the Color property of my DropShadowEffect.
但是,我似乎无法绑定我的DropShadowEffect的Color属性。 Could anyone suggest why this doesn't work?
谁能说出为什么这行不通?
XAML ; XAML ;
<ControlTemplate x:Key="ActiveEffectTemplate" TargetType="{x:Type Controls:ImageButton}">
<Image Name="image" Source="{TemplateBinding ImageSource}">
<Image.Effect>
<DropShadowEffect
Color="{Binding HighlightColour}"
BlurRadius="20"
ShadowDepth="0"
Opacity="1"
Direction="0"/>
</Image.Effect>
</Image>
</ControlTemplate>
Code behind; 后面的代码;
public static readonly DependencyProperty HighlightColourProperty =
DependencyProperty.Register("HighlightColour", typeof(Color), typeof(ImageButton));
public Color HighlightColour
{
get { return (Color)GetValue(HighlightColourProperty); }
set { SetValue(HighlightColourProperty, value); }
}
我相信我通过将以下内容放入绑定中解决了这个问题;
RelativeSource={RelativeSource AncestorType={x:Type Controls:ImageButton}}
该绑定是相对于DataContext
,它可能也应该只是一个TemplateBinding
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.