WPF - Scrollviewer.ComputedVerticalScrollBarVisibility doesn't change in a loop

13 hours ago 1
ARTICLE AD BOX

I'm new to WPF. I have a Usercontrol made of white border, a ScrollViewer and a RichTextBox in it, which supposed to display a footnote text when the mouse is over the footnote special sign in the text.

<Grid> <Border Background="White" CornerRadius="8" Opacity="0.9"> <ScrollViewer Name="scrol" VerticalScrollBarVisibility="Auto" Margin="8"> <RichTextBox Name="rtfFootnote" Foreground="{StaticResource TextColor}" BorderThickness="0" FontSize="14"/> </ScrollViewer> </Border> </Grid>

Now, I want the RichTextBox to be in the size of the footnote text, not too big and not too small. Therefore I create the Control small, and in a While loop I enlarge it and check if the ComputedVerticalScrollBarVisibility value of the ScrollViewer Visibility is set to other value than Visible. In Winforms it worked, but here it never happens.

while (scrol.ComputedVerticalScrollBarVisibility == Visibility.Visible) { this.Width = this.Width + 20; currentTop -= 10; Canvas.SetTop(this, currentTop); this.Height = this.Height + 10; }

I've checked the RTB and it is growing together with the UserControl. let's say, if I write

while (scrol.ComputedVerticalScrollBarVisibility == Visibility.Visible && Width < 500)

It shows finally all the text, with an unnecessary space.

Can someone help me?

Read Entire Article