I would like to set ToolTip maxwidth property to show long texts properly. In addition I need text wrapping. I used this style:
<Style TargetType="ToolTip">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}" MaxWidth="400" TextWrapping='Wrap' />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
This tooltip style is OK for my purpose. However, it is not effective for some controls which has own tooltip style. For example, tooltip of following button can not appear.
<Button>
<Button.ToolTip>
<StackPanel>
<TextBlock Style="{StaticResource firstText}" Text="aaaaaaaaaaaaa"/>
<TextBlock Style="{StaticResource secondText}" Text="bbbbbbbbbbbbb"/>
<TextBlock Bacground="Red" Text="ccccccccccccc"/>
</StackPanel>
</Button.ToolTip>
</Button>
I want to set maxwidth property with text wrapping for all tooltips. What can i do for this issue?
I avoid using Template because a lot things must be implement. So more elegant way to do that
<Style TargetType="ToolTip">
<Style.Resources>
<Style TargetType="ContentPresenter">
<Style.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</Style.Resources>
</Style>
</Style.Resources>
<Setter Property="MaxWidth" Value="500" />
</Style>
I realise that this is an old question, but no one seems to have suggested the most obvious and simplest solution to this problem yet. As such, I thought I'd add it here:
<Button>
<Button.ToolTip>
<ToolTip MaxWidth="400">
<TextBlock Text="{Binding Binding}" TextWrapping="Wrap" />
</ToolTip>
</Button.ToolTip>
</Button>
Following style of ToolTip is useful for me:
<Style TargetType="ToolTip" x:Key="InternalToolTipStyle">
<Setter Property="MaxWidth" Value="{Binding Path=(lib:ToolTipProperties.MaxWidth)}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<ContentPresenter Content="{TemplateBinding Content}" >
<ContentPresenter.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
With this style, tooltip of following button appears properly:
<Button>
<Button.ToolTip>
<StackPanel>
<TextBlock Style="{StaticResource firstText}" Text="aaaaaaaaaaaaa"/>
<TextBlock Style="{StaticResource secondText}" Text="bbbbbbbbbbbbb"/>
<TextBlock Bacground="Red" Text="ccccccccccccc"/>
</StackPanel>
</Button.ToolTip>
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