Answered ToolTip with multi-line

  • Tuesday, March 04, 2008 3:40 PM
     
     

     

    Hi,

    How do I make a multi-line tooltip ?

    I tried to set the ToolTip property of a control to:

     

    ToolTip="AAA\r\nBBB"

     

    but it does not work.

     

    Yoav.

All Replies

  • Tuesday, March 04, 2008 3:43 PM
     
     

    Just set something more practical as a tooltip (it takes an object, UIElements are rendered, all others are displayed as ToString)

    Code Snippet

     

    <Button Content="Hello">

      <Button.ToolTip>

        <TextBlock

          Line1<LineBreak/>

         Line2

      </TextBlock>

    </Button.ToolTip>

    </Button>

     

     

     

  • Wednesday, March 05, 2008 6:20 AM
     
     

    Thanks.

    But now I have another problem:
    I need to recieve the tootip text from code.

    I tried to do:

     

    Code Snippet

    <Button Content="Hello">

      <Button.ToolTip>

        <TextBlock Text="{Binding Path=ToolTipText, ElementName=window, Mode=Default}"/>

      </Button.ToolTip>

    </Button>

     

     

    But the binding does not work

    (I also tried to use Label instead of TextBlock)

  • Wednesday, March 05, 2008 12:58 PM
     
     

    Hi.. I had that problem. Ended seeing the "\n" written into the tooltips.

    Solved by doing this to the string I passed to the tooltip:

     

    Code Snippet

    ToolTip = MyString.Replace("\\n","\n");

     

  • Thursday, March 06, 2008 5:23 AM
    Moderator
     
     Answered

    You can try the following example, which works well. Futhermore, we should use System.Environment.NewLine property to add new line in a string.

     

    Code Snippet

    <Window

       x:Class="ForumProjects.MainWindow"

       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

       Title="MainWindow" Width="800" Height="600">

        <StackPanel>

            <TextBox x:Name="TB" AcceptsReturn="True" Text="{Binding WindowText, ElementName=Window, UpdateSourceTrigger=PropertyChanged}"/>

            <Button ToolTip="{Binding WindowText, ElementName=Window, Mode=OneWay}">Test</Button>

        </StackPanel>

    </Window>

     

    namespace ForumProjects

    {

        public partial class MainWindow : Window

        {

            public MainWindow()

            {

                InitializeComponent();

            }

     

            public string WindowText

            {

                get { return (string)GetValue(WindowTextProperty); }

                set { SetValue(WindowTextProperty, value); }

            }

            public static readonly DependencyProperty WindowTextProperty =

                DependencyProperty.Register("WindowText", typeof(string), typeof(MainWindow), new FrameworkPropertyMetadata());

        }

    }

     

     

    Best Regards,

    Wei Zhou

  • Wednesday, October 22, 2008 11:55 AM
     
     
    Hi,

    I tried all ... <LineBreak/>.. \n , \\n... etc..
    only environment.newline worked for me...

    I have used a string table to keep all my tool tip in my system...
    few of the tool tips are long and need multi-line support..
     from c# i used this...

    myelement.ToolTip = MyStringTable.SOME_CELL_TOOLTIP.Replace("<LineBreak/>",Environment.NewLine);

     

    Regards

    Munna

    Md. Masudur Rahman
  • Thursday, September 17, 2009 11:39 PM
     
     Proposed
    Hi,

    I had this issue as well, and wanted to do everything XAML.  This is what worked for me:

    ToolTip="Line 1&#xa;Line 2&#xa;Line 3&#xa;Line 4"

    The tooltip then reads:

    Line 1
    Line 2
    Line 3
    Line 4

    Hope this helps!
    Ed Clapper
    • Proposed As Answer by bhayes22 Wednesday, January 13, 2010 9:33 PM
    •  
  • Friday, November 05, 2010 12:20 AM
     
     
    Really helpful, thanks Ed!
  • Friday, May 20, 2011 11:37 AM
     
     
    This really worked... Thanks a lot Ed Clapper!!!!
  • Tuesday, October 02, 2012 3:15 AM
     
     Proposed

    solution>

    use breakline with '&#13;'


    Evandro de Almeida Tartari se a informação for util marcar como resposta por gentileza =)

    • Proposed As Answer by Mike Poz Thursday, October 11, 2012 11:10 PM
    •