I have TemplatedControl with Dependency Property:
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
"Color", typeof(SolidColorBrush), typeof(MenuButton), new PropertyMetadata(default(SolidColorBrush)));
public SolidColorBrush Color
{
get { return (SolidColorBrush)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
In the style I want to use this property to set Background. I tried:
<Style TargetType="controls:MenuButton" x:Name="MenuButtonSimple">
<Setter Property="Background" Value="{Binding Color, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
and
<Style TargetType="controls:MenuButton" x:Name="MenuButtonSimple">
<Setter Property="Background" Value="{TemplateBinding Color}"/>
but it doesn't work.
If I set fixed color in the template - it works:
<Style TargetType="controls:MenuButton" x:Name="MenuButtonSimple">
<Setter Property="Background" Value="667788"/>
How can I use dependency property (Color) in the style ?
Aucun commentaire:
Enregistrer un commentaire