本文介绍了使用DropShadowEffect的WPF Image“高亮”不能绑定颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个名为 ImageButton 的UserControl,我在MouseOver上使用DropShadowEffect将该按钮显示为活动。但是,我似乎无法绑定我的DropShadowEffect的Color属性。可能有人建议为什么这不起作用?
I have created a UserControl called ImageButton, and I am using a DropShadowEffect on MouseOver to show the button as 'active'. However, I cannot seem to bind the Color property of my DropShadowEffect. Could anyone suggest why this doesn't work?
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>
代码背后;
public static readonly DependencyProperty HighlightColourProperty =
DependencyProperty.Register("HighlightColour", typeof(Color), typeof(ImageButton));
public Color HighlightColour
{
get { return (Color)GetValue(HighlightColourProperty); }
set { SetValue(HighlightColourProperty, value); }
}
推荐答案
我相信我解决了这个通过将以下内容放入我的绑定中:
I believe I solved this problem by putting the following into my binding;
RelativeSource={RelativeSource AncestorType={x:Type Controls:ImageButton}}
这篇关于使用DropShadowEffect的WPF Image“高亮”不能绑定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!