How can you turn on word wrap for all hints in Silverlight 4?

In my Silverlight 4 app, I have a few long tooltips. By default, these tooltips show one very long line. For example:

<TextBox Text="Test1" ToolTipService.ToolTip="One tasdg asdg as da sdg asdg asdg asdg asd gas dg a sdg a sdg a sd a sd g asdasdgasdg sadgasdgasdg asdg asdg asd as a sd ga sdg asd g asd g asd g asdgasdg asdgasdg"/> 

I would like to make tooltips appear on multiple lines. One way to achieve this is to define a tooltip using a TextBlock. For example:

  <TextBox Text="Test2"> <ToolTipService.ToolTip> <TextBlock TextWrapping="Wrap" Width="200" Text="One tasdg asdg as da sdg asdg asdg asdg asd gas dg a sdg a sdg a sd a sd g asdasdgasdg sadgasdgasdg asdg asdg asd as a sd ga sdg asd g asd g asd g asdgasdg asdgasdg"/> </ToolTipService.ToolTip> </TextBox> 

To do this for each control that I want to define a tooltip seems to be a lot of work. Ideally, I would like to define tooltips as strings similar to the first example, and then apply the style that applies to all tooltips around the world, which will make tooltips. So in my App.xaml, I would define something like this:

  <Style TargetType="ToolTip"> <!-- Somehow make all tooltips wrap at a width of 200 --> </Style> 

Any tips on how I can do this?

+6
coding-style tooltip silverlight textwrapping
source share
1 answer

You can create an implicit style for the tooltip and set the content template to something suitable - for example

 <Style TargetType="ToolTip"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <TextBlock TextWrapping="Wrap" Width="200" Text="{Binding}" /> </DataTemplate> </Setter.Value> </Setter> </Style> 

Then you can use something like:

 <TextBox Text="Test2" ToolTipService.ToolTip="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg " /> 
+14
source share

All Articles