Reputation: 738
I have a TextBlock which has Style={TemplateBinding ParentDependencyProperty}
I need to place some DataTriggers on just this TextBlock, but not on the style as a whole.
I need something like this:
<TextBlock>
<Style BasedOn="StyleInParentDependencyProperty">
<Style.Triggers>
...
</Style.Triggers>
</Style>
</TextBlock>
And I can't figure out how, as no bindings are allowed in the BasedOn property of Styles. I am pretty new to WPF, and seemingly stuck here.
Thanks for your help.
Upvotes: 0
Views: 320
Reputation: 10865
You can do something like this
<Style TargetType="TextBlock" x:Key="Default">
<Setter Property="Background" Value="Red"></Setter>
<Setter Property="FontFamily" Value="Segoe Black" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontSize" Value="32pt" />
<Setter Property="Foreground" Value="#777777" />
</Style>
And define this style just on your TextBlock
that need some DataTriggers
<Style BasedOn="{StaticResource Default}" TargetType="TextBlock" x:Key="TextBlockWithTriggers">
<Style.Triggers> .... </Style.Triggers>
</Style>
And on your TextBlock
just define
<TextBlock Style="{StaticResource TextBlockWithTriggers}"/>
Upvotes: 2