我已经创建了一个名为ImageButton的UserControl,我在MouseOver上使用dropshadoweeffect来显示按钮为"活动"。然而,我似乎不能绑定我的dropshadoweeffect的Color属性。谁能告诉我为什么这不起作用?
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); }
}
我相信我已经解决了这个问题,在我的绑定中加入了以下内容;
RelativeSource={RelativeSource AncestorType={x:Type Controls:ImageButton}}
这个绑定是相对于DataContext
的,它也应该只是一个TemplateBinding