locked
Count symbols in RichTextBlock WinRT RRS feed

  • Question

  • I have a RichTextBlock with some text.I dont want use vertical and horizontal scrolls. If I add a large text, some text is hiding. How can I get hidden text or how can I get current not hided text? Size of my RichTextBlock set dynamically.
    Monday, November 25, 2013 10:13 PM

Answers

  • Hi MaxChase,

    For instance we have a RichTextBlock (filled in with some context) and a RichTextBlockOverflow:

    <RichTextBlock x:Name="rtb" OverflowContentTarget="{Binding ElementName=rtbof}" HorizontalAlignment="Left" Height="38" Margin="796,234,0,0" VerticalAlignment="Top" Width="56">
       <Paragraph>
           <Run Text="RichTextBlock111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"/>
       </Paragraph>
    </RichTextBlock>
    <RichTextBlockOverflow x:Name="rtbof" HorizontalAlignment="Left" Height="165" Margin="796,365,0,0" VerticalAlignment="Top" Width="369"/>
            

    We can use the following C# code to get the TextPointer, and use Select function to get the text, here you go.

    var start = rtbof.ContentStart; var end = rtbof.ContentEnd;

    rtb.Select(start, end);
    var textYouNeed = rtb.SelectedText;

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by MaxChase Tuesday, November 26, 2013 1:37 PM
    Tuesday, November 26, 2013 9:48 AM
    Moderator

All replies

  • Hi MaxChase,

    Yes, you can, RichTextBlock has HasOverflowContent and you could bind the overflow content to the RichTextBlockOverflow by following statement:

    RichTextBlock OverflowContentTarget="{Binding ElementName=nameOfTarget}" />
    
    

    And then you could use ContentStart and ContentEndfor RichTextBlockOverflow to know the TextPointer .

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, November 26, 2013 3:06 AM
    Moderator
  • Hi,James.
    Can you tell how get this text? I understand about contentstart and contentend, but I dont understand how I should use it.
    Tuesday, November 26, 2013 8:29 AM
  • Hi MaxChase,

    For instance we have a RichTextBlock (filled in with some context) and a RichTextBlockOverflow:

    <RichTextBlock x:Name="rtb" OverflowContentTarget="{Binding ElementName=rtbof}" HorizontalAlignment="Left" Height="38" Margin="796,234,0,0" VerticalAlignment="Top" Width="56">
       <Paragraph>
           <Run Text="RichTextBlock111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"/>
       </Paragraph>
    </RichTextBlock>
    <RichTextBlockOverflow x:Name="rtbof" HorizontalAlignment="Left" Height="165" Margin="796,365,0,0" VerticalAlignment="Top" Width="369"/>
            

    We can use the following C# code to get the TextPointer, and use Select function to get the text, here you go.

    var start = rtbof.ContentStart; var end = rtbof.ContentEnd;

    rtb.Select(start, end);
    var textYouNeed = rtb.SelectedText;

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by MaxChase Tuesday, November 26, 2013 1:37 PM
    Tuesday, November 26, 2013 9:48 AM
    Moderator
  • Thank you very much!
    Tuesday, November 26, 2013 1:37 PM