I just need a simple ToolTip WPF style that displays multiple lines

Because of all the noise from the fantasy, super, huge and blah blah blah blah, tooltips I can not find the answer.

I just need a simple style that sets TextWrapping="Wrap" and allows me to set the width.

One that duplicates an existing default style / style, but only word wraps.

+7
source share
3 answers
 <Window.Resources> <Style TargetType="{x:Type ToolTip}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <TextBlock TextWrapping="Wrap" Text="{Binding}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Rectangle Width="100" Height="100" Fill="Red"> <Rectangle.ToolTip> <ToolTip Width="100"> This is some text with text wrapping. </ToolTip> </Rectangle.ToolTip> </Rectangle> </Grid> 

This example assumes that you want to set the width for each use. If you want to set it as part of the style, add it to the TextBlock element.

+8
source

This style prevents the tooltip from appearing on empty lines.

 <Style TargetType="ToolTip"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToolTip"> <TextBlock Text="{TemplateBinding Content}" MaxWidth="400" TextWrapping="Wrap"/> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Content" Value=""> <Setter Property="Visibility" Value="Collapsed" /> </Trigger> </Style.Triggers> </Style> 

Or using the ContentTemplate:

 <Style TargetType="{x:Type ToolTip}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <StackPanel> <TextBlock Text="{Binding}" MaxWidth="400" TextWrapping='Wrap' /> </StackPanel> </DataTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Content" Value=""> <Setter Property="Visibility" Value="Collapsed" /> </Trigger> </Style.Triggers> </Style> 
+3
source

If you just want to get the effects below, read this post .

enter image description hereenter image description hereenter image description here

+2
source

All Articles