locked
Link between TextBlocks RRS feed

  • Question

  • Is it possible to link two TextBlocks so that the content of the first TextBlock can "flow" into the second TextBlock (if the first one is too small)?
    Or is there even an easy way to detect an overflow of text content in a TextBlock (or RichTextBox)?

    Thanks in advance!
    Monday, January 4, 2010 4:43 PM

Answers

  • you can use the viewportheight and  compare it with the extentheight to determine if there is an overflow....
    Tuesday, January 5, 2010 5:14 AM
  • you would then use the viewportwidth with the extentwidth
    Tuesday, January 5, 2010 3:58 PM

All replies

  • I hope this will help you :)

    http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.texttrimming.aspx

    Prasad - www.beautifulmind.blog.co.in
    Microsoft MVP
    • Proposed as answer by prasad22 Tuesday, January 5, 2010 3:01 AM
    Tuesday, January 5, 2010 3:01 AM
  • It doesn't sound like you are looking for text trimming as the other poster suggested but you are more interested in knowing with text trimming would occur so that you can do some custom action.

    This sounds like a strange scenario but what I could think of to do is create your own control that inherits from TextBox and supplies a new control template with the primary TextBox and the overflow TextBox. Then hook into the OntextChanged event of the primary text box and do your own arrange pass. This would give the ability to determine if trimming is needed (bascially if the text supplied will overflow the primary text box).

    From there you could determine which text should go into the overflow box and then do what you want to get the visual you are looking for.

    I did some basic text trimming in Silverlight 2 a while back and the concept of what you are trying to do will be the same. You can see my blog entry about it here
    http://www.bradcunningham.net/2009/07/texttrimming-in-silverlight-2.html


    The reason I first stated that this is strange is that the overflow box would almost certianly have to be read only as allowing intput into both boxes would cause lot of other complications. Also, you willhave to consider what to do when the use deletes text and when the font sizes / styles changes (which will casue trimming logic to be much more complicated)


    Hope that helps.

    Tuesday, January 5, 2010 4:41 AM
  • you can use the viewportheight and  compare it with the extentheight to determine if there is an overflow....
    Tuesday, January 5, 2010 5:14 AM
  • That would make sense for multi line text but not for single line text correct? Or m I missing something? In a single line scenario you would have to look at the Width property regardless of Height correct?
    Tuesday, January 5, 2010 5:15 AM
  • you would then use the viewportwidth with the extentwidth
    Tuesday, January 5, 2010 3:58 PM