locked
RichTextBlock.HasOverflowContent is never true

    Question

  • Hello.

    I make fb2reader and i have task: divide my text to parts, which as it will be book's pages for the user.

    I wrote algoritm, what divide text for spaciousness of RichTextBlock using RichTextBlock.HasOverflowContent and i tested it in code-behind.

    Now i need to create List<RichTextBlock> with content. This will be my "book pages" and then this will be items source for FlipView.

    But, when i create richtextblock programatically, it never has HasOverflowContent is true; as if it were a rubber. Why???

    How I can solve this problem? Help me please!

    Tuesday, September 09, 2014 4:20 PM

Answers

  • Hi Danil,

    I would suggest you with binding to RichTextBlockOverflow instead of separate contents programmatically if you use them in one page. Furthermore, you could test HasOverflowContent to see if you need create another RichTextBlockOverflow for your rest content.

    For your question, where you put the method? I use it with Page_loaded and everything works fine, a true value has been returned. You have to ensure that the control is loaded and then get the value.

    A similar question: http://social.msdn.microsoft.com/forums/windowsapps/en-us/639dfd99-ff82-41dc-8594-22a5482fcb7a/richtextblockhasoverflowcontent-is-always-false

    --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.

    Wednesday, September 10, 2014 10:40 AM
    Moderator
  • Hi Danil,

    I could reproduce your issue if I get property before the content is rendered to UI.

    I think the reason is similar as you get that property in constructor function. If you get the property after the content was rendered, you should find the value is correct.

    Is that the case?

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                var paragraph1 = new Paragraph();
    
                var run1  = new Run();
    
                run1.Text = "Hello World";
    
                var span1 = new Span();
    
                span1.Inlines.Add(run1);
    
                var bold1 = new Bold();
    
                bold1.Inlines.Add(span1);
    
                var run2 = new Run();
    
                run2.Text = @" , consectetur adipiscing elit. Sed ac mi ipsum. Phasellus vel malesuada mauris. Donec pharetra, enim sit amet mattis tincidunt, felis nisi semper lectus, vel porta diam nisi in augue. Pellentesque lacus tortor, aliquam et faucibus id, rhoncus ut justo. Sed id lectus odio, eget pulvinar diam. Suspendisse eleifend ornare libero, in luctus purus aliquet non. Sed interdum, sem vitae rutrum rhoncus, felis ligula ultrices sem, in eleifend eros ante id neque. Vivamus quam lorem, varius vitae porta mollis, placerat quis est. Aenean eget sagittis massa. Sed tellus turpis, ullamcorper eget imperdiet vel, faucibus vel nisl. Nunc sed suscipit quam. Vivamus convallis faucibus dignissim. Fusce sollicitudin, quam vel cursus mattis, nisl velit tristique sapien, ac vestibulum ante arcu a nisl. Vestibulum commodo gravida ante at tincidunt. Vestibulum in ornare nunc. Nullam ut lorem vitae dui placerat lacinia sit amet a arcu. Nulla sit amet odio nisi. Praesent erat urna, venenatis ac adipiscing vel, congue at lectus. Proin ac metus at quam luctus ultricies.";
    
                paragraph1.Inlines.Add(bold1);
    
                paragraph1.Inlines.Add(run2);
    
                DynamicRtb.Blocks.Add(paragraph1);
    
                // if I get the HasOverflowContent here, it will always return false
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                var hasOver = DynamicRtb.HasOverflowContent;
                // if I get it after the content be renderd, it will return the correct value
            }

    Wednesday, September 10, 2014 12:31 PM

All replies

  • Hi Danil,

    I would suggest you with binding to RichTextBlockOverflow instead of separate contents programmatically if you use them in one page. Furthermore, you could test HasOverflowContent to see if you need create another RichTextBlockOverflow for your rest content.

    For your question, where you put the method? I use it with Page_loaded and everything works fine, a true value has been returned. You have to ensure that the control is loaded and then get the value.

    A similar question: http://social.msdn.microsoft.com/forums/windowsapps/en-us/639dfd99-ff82-41dc-8594-22a5482fcb7a/richtextblockhasoverflowcontent-is-always-false

    --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.

    Wednesday, September 10, 2014 10:40 AM
    Moderator
  • My problem was in the not  cause in RichTextBlock.Measure(...);
    Wednesday, September 10, 2014 10:53 AM
  • Hi Danil,

    I could reproduce your issue if I get property before the content is rendered to UI.

    I think the reason is similar as you get that property in constructor function. If you get the property after the content was rendered, you should find the value is correct.

    Is that the case?

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                var paragraph1 = new Paragraph();
    
                var run1  = new Run();
    
                run1.Text = "Hello World";
    
                var span1 = new Span();
    
                span1.Inlines.Add(run1);
    
                var bold1 = new Bold();
    
                bold1.Inlines.Add(span1);
    
                var run2 = new Run();
    
                run2.Text = @" , consectetur adipiscing elit. Sed ac mi ipsum. Phasellus vel malesuada mauris. Donec pharetra, enim sit amet mattis tincidunt, felis nisi semper lectus, vel porta diam nisi in augue. Pellentesque lacus tortor, aliquam et faucibus id, rhoncus ut justo. Sed id lectus odio, eget pulvinar diam. Suspendisse eleifend ornare libero, in luctus purus aliquet non. Sed interdum, sem vitae rutrum rhoncus, felis ligula ultrices sem, in eleifend eros ante id neque. Vivamus quam lorem, varius vitae porta mollis, placerat quis est. Aenean eget sagittis massa. Sed tellus turpis, ullamcorper eget imperdiet vel, faucibus vel nisl. Nunc sed suscipit quam. Vivamus convallis faucibus dignissim. Fusce sollicitudin, quam vel cursus mattis, nisl velit tristique sapien, ac vestibulum ante arcu a nisl. Vestibulum commodo gravida ante at tincidunt. Vestibulum in ornare nunc. Nullam ut lorem vitae dui placerat lacinia sit amet a arcu. Nulla sit amet odio nisi. Praesent erat urna, venenatis ac adipiscing vel, congue at lectus. Proin ac metus at quam luctus ultricies.";
    
                paragraph1.Inlines.Add(bold1);
    
                paragraph1.Inlines.Add(run2);
    
                DynamicRtb.Blocks.Add(paragraph1);
    
                // if I get the HasOverflowContent here, it will always return false
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                var hasOver = DynamicRtb.HasOverflowContent;
                // if I get it after the content be renderd, it will return the correct value
            }

    Wednesday, September 10, 2014 12:31 PM