If I assign a piece of text to the Content
property of a ContentPresenter
, a TextBlock
control is generated by the ContentPresenter
at render time to contain that text.
If I create a style that applies toTextBlock
properties and assign it to that ContentPresenter
, the does not appear to apply to the implicitly generated TextBlock
s.
<Style x:Key="SampleStyle">
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
</Style>
<ContentPresenter Content="This is a Test piece of text." Style="{StaticResource SampleStyle}"/>
Is there a way to apply this style successfully to the autogenerated TextBlock
s short of applying it to all TextBlock
s (e.g. declaring style as TargetType="TextBlock"
with no Key
)?
You can do this...
...then where you define your
ContentPresenter
...The
TargetType
is set since as you know theContentPresenter
will not always hold aTextBlock
in it.If you are not using the style elsewhere, you could apply it directly to the content presenter: