Home > OS >  Scrollviewer scrollbars not showing and needs to
Scrollviewer scrollbars not showing and needs to

Time:10-08

Why do the scrollbars not appear with the following XAML?

<Window x:Class="GridViewsToImagePocApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlna:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="600" Width=800">
    <StackPanel>
        <ScrollViewer IsEnabled="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
            <StackPanel>
                <telerik:RadGridView x:Name="GridView1" AutoGenerateColumns="True" />
                <telerik:RadGridView x:Name="GridView2" AutoGenerateColumns="True" Margin="0 15 0 0" />
                <telerik:RadGridView x:Name="GridView3" AutoGenerateColumns="True" Margin="0 15 0 0" />
                <telerik:RadGridView x:Name="GridView4" AutoGenerateColumns="True" Margin="0 15 0 0" />
                <telerik:RadGridView x:Name="GridView5" AutoGenerateColumns="True" Margin="0 15 0 0" />
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
</Window>

CodePudding user response:

The outer StackPanel is the issue. It measures its children with positive infinity (height in Vertical Orientation or width in Horizontal orientation). Hence the ScrollViewer is not restricted in any way, so it expands to fit its content and does not need to display any scrollbars.

Use a panel that restricts the size of the ScrollViewer to the available space instead, like Grid, UniformGrid or DockPanel, depending on your requirements.

<Grid>
   <ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
      <StackPanel>
         <!-- ...your content. -->
      </StackPanel>
   </ScrollViewer>
</Grid>
  • Related