0
Answer

Unable to view scrollbar inside WPF child page

Sandip Patel

Sandip Patel

10y
603
1
In my existing application, I have used navigation. For that, I have one main window and different pages inside that to be loaded in a frame element. Here, when the number of controls increase in the page; I want a scroll bar in the page. But currently it appears for the window.Also, in my current code there are 3 columns in SplitGrid - a grid. I want that first column to be 25% and third column to be 75% width of the available screen area. Is it possible here?
Parent Window :
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" ></RowDefinition> </Grid.RowDefinitions> <StackPanel Orientation="Vertical" HorizontalAlignment="Center"> <TextBlock FontSize="24" HorizontalAlignment="Center" Text="Ribbon - (Main Menu + Sub Menu)" FontWeight="Bold"/> <Button Content="Test Button" Click="Button_Click" Width="100" Height="50" HorizontalContentAlignment="Center" VerticalAlignment="Center" /> </StackPanel> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Row="1"> <Grid Grid.Row="1"> <Grid.RowDefinitions> <RowDefinition Height="*" ></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid Name="SplitGrid"> <Grid.RowDefinitions> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" MinWidth="350" ></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <Border BorderBrush="#DEB887" BorderThickness="2" CornerRadius="10" Grid.Column="0" HorizontalAlignment="Stretch"> <Border.Background> <LinearGradientBrush EndPoint="0.5,0.9" StartPoint="0.5,0"> <GradientStop Color="#306EFF" Offset="0.9" /> <GradientStop Color="#BDEDFF" /> </LinearGradientBrush> </Border.Background> <StackPanel Orientation="Vertical"> <Border BorderThickness="2" CornerRadius="8" Margin="5,15,5,10" x:Name="InnerBorder"> <Border.Background> <LinearGradientBrush EndPoint="0.5,0.9" StartPoint="0.5,0"> <GradientStop Color="#F0FFFF" Offset="0.9" /> <GradientStop Color="#EBF4FA" /> </LinearGradientBrush> </Border.Background> <ScrollViewer VerticalScrollBarVisibility="Auto" > <StackPanel Orientation="Vertical" Margin="0,0,0,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Frame NavigationUIVisibility="Automatic" Name="frmContent" Source="MainPage.xaml" /> </StackPanel> </ScrollViewer> </Border> </StackPanel> </Border> <GridSplitter Grid.Column="1" Name="grdSplitter" Background="#3976FF" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" Visibility="Visible" Width="5" /> <StackPanel Background="Blue" Grid.Column="2"></StackPanel> </Grid> </Grid> </ScrollViewer> </Grid>

MainPage
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> <WrapPanel MinWidth="150" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}" HorizontalAlignment="Stretch"> <Button Width="200" Height="50" Content="Button 1"/> ..... <Button Width="180" Height="50" Content="Button 20"/> </WrapPanel> </ScrollViewer>