does anyone know the difference between defining a vertical scrollbar on a frame like this:
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
<Frame Name="Frame1"
ScrollViewer.CanContentScroll="True" />
</ScrollViewer>
or like this:
<ScrollViewer Grid.Row="2">
<Frame Name="Frame1"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True" />
</ScrollViewer>
This frame is nested in a WebBrowser control and setting it the first way correctly displays the vertical scrollbar and is only visible when it needs to scroll (auto). When I set it the second way the vertical scrollbar works but is always visible even when it does not need to scroll (visible).
I am going to use the 1st option because it meets my needs, but I don't want to be surprised down the road if I am setting it incorrectly.
Thanks!
How to enable scrollbar in a WPF TextBox. The simplest way to add scrolling functionality to a TextBox control is by enabling its horizontal and vertical scrolling. The HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties are used to set horizontal and vertical scroll bars of a TextBox.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
There are two predefined elements that enable scrolling in WPF applications: ScrollBar and ScrollViewer. The ScrollViewer control encapsulates horizontal and vertical ScrollBar elements and a content container (such as a Panel element) in order to display other visible elements in a scrollable area.
When you use ScrollViewer.VerticalScrollBarVisibility
or ScrollViewer.HorizontalScrollBarVisibility
attached property it has no effect with Frame.
<ScrollViewer Margin="225.667,-4,0,296.939" HorizontalAlignment="Left" Width="221.667">
<Frame Content="Frame" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Hidden" Source="UserControl2.xaml" Background="#FFDE5454"/>
</ScrollViewer>
In example above I used both ScrollViewer.VerticalScrollBarVisibility
and ScrollViewer.HorizontalScrollBarVisibility
attached properties. outcome of that code is the exact opposite of what you would expect. There is no HorizontalScrollBar
visible... and you can still see VerticalScrollBar
.
So that's why this is what you should use
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
<Frame Name="Frame1" />
</ScrollViewer>
When you try this for example with ListBox then result will be different.
This is the result of following code:
<ScrollViewer Margin="225.667,0,0,12.761" Height="280.178" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="221.667">
<ListBox ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" Background="Orange" ItemsSource="{Binding Collection}" DisplayMemberPath="Property1" />
</ScrollViewer>
That's because those attached properties now affect ScrollViewer within ListBox
and not parent ScrollViewer
as you may expect.
So from this little experiment I assume that ScrollViewer.VerticalScrollBarVisibility
attached property is meant for cases where you want to be able to affect ScrollViewer
which exists within Control's template and not parent ScrollViewer
. So I think it does not work for example as DockPanel.Dock
which takes effect on parent DockPanel
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With