Use the same style for the TextBlock and Run element.

I have a WPF style that sets a dependency property TextDecorationsfor TargetType: TexBlock. I need to use the same style for certain Run elements that are in some TextBlock, which itself does not use the above style. How can I achieve this without repeating the same style with another TargetType?

+5
source share
1 answer

Just do not specify TargetType, but qualify the property, for example:

<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>

, BasedOn, , .

+5

All Articles