ContentControl Wrapping Issue

.net, c#, wpf, wpf-controls, xaml

Solution

Replace `ContentControl` tag with:

<ContentPresenter Content="{TemplateBinding HelpContent}">
    <ContentPresenter.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
    </ContentPresenter.Resources>
</ContentPresenter>

[Note: you can leave it as a `ContentControl`, but `ContentPresenter` is lighter and follows conventions]

Problem

I am trying to create a Custom tooltip Control. This control is inherited from ToolTip class. My Custom Tooltip will have a header and a content area. Content could be normal text or any other content (Image, richtextbox etc). Following is the Template Style that custom tooltip control. ``` <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type customControls:FlyoutHelp}"> <Border BorderThickness="0" Margin="15" Width="300"> <Border.Effect> <DropShadowEffect Opacity="0.7" /> </Border.Effect> <StackPanel TextBlock.FontFamily="Trebuchet MS" TextBlock.FontSize='12'> <TextBlock Background="{StaticResource DellBlue}" Height="23" Foreground="#FFFFFF" Padding="0,4,0,0" TextAlignment="Center" Text="{Binding HeaderText, RelativeSource={RelativeSource Mode=TemplatedParent}}" /> <Border Background="{StaticResource DellLightGrey}" TextBlock.Foreground="{StaticResource DarkestGrey}" Padding="8"> <ContentControl Content="{Binding HelpContent, RelativeSource={RelativeSource Mode=TemplatedParent}}" /> </Border> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> ``` Now as you can see in my template that I am using ContentControl for showing the content of the tooltip. The problem is when my HelpContent is just plain String, it doesn't wrap that text. I can't replace ContentControl with TextBlock because HelpContent could be some other type too (image, richtextbox etc). Can anyone please provide me what is the best way to fix this problem? I will be really very thankful.

Original source