I have a WPF style that sets TextDecorations
dependency property for TargetType: TexBlock
. I need to use the same style for certain Run elements which are in some TextBlock which doesn't itself use the aforementioned style. How can I achieve this without repeating the same style with just a different TargetType
?
Just do not specify a TargetType
but qualify the property, e.g.:
<Style x:Key="CommonStyle">
<Setter Property="Inline.TextDecorations" Value="StrikeThrough" />
</Style>
<TextBlock Style="{StaticResource CommonStyle}" Text="Lorem Ipsum" />
<TextBlock>
<Run Style="{StaticResource CommonStyle}" Text="Lorem" />
<Run Text="Ipsum" />
</TextBlock>
If you want to further develop the style you can use BasedOn
, this also allows implicit application of said style by not setting a key on the derived style.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With