Effect Template Binding
Should I be able to template bind color to an effect object? I am able to bind other properties but with effects and color I can't seem to get it to work. I also tried brushes using SolidColorBrush. Thank you!
// Style
// User Control
// usage
// Style
Code: Select all
<Style TargetType="local:RadialRangeControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:RadialRangeControl">
<Path Name="PART_Value"
<Path.Effect>
<DropShadowEffect BlurRadius="15" ShadowDepth="0" Opacity="1" Color="{TemplateBinding ValueShadowColor}"/>
</Path.Effect>
</Path>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Code: Select all
public static readonly DependencyProperty ValueShadowColorProperty =
DependencyProperty.Register(nameof(ValueShadowColor), typeof(Color), typeof(RadialRangeControl), new PropertyMetadata(Colors.Transparent));
public Color ValueShadowColor
{
get { return (Color)GetValue(ValueShadowColorProperty); }
set { SetValue(ValueShadowColorProperty, value); }
}
Code: Select all
<local:RadialRangeControl ValueShadowColor="Red" />
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Effect Template Binding
TemplateBinding only works on Controls as they expose the TemplatedParent property.
If you want to bind an effect (or brush, etc.) property to the templated parent you should use a regular binding with RelativeSource:
If you want to bind an effect (or brush, etc.) property to the templated parent you should use a regular binding with RelativeSource:
Code: Select all
<DropShadowEffect BlurRadius="15" ShadowDepth="0" Opacity="1"
Color="{Binding ValueShadowColor, RelativeSource={RelativeSource TemplatedParent}}"/>
Re: Effect Template Binding
Thank you!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 66 guests