How to scroll a grid line in WPF / XAML?

Hi and thanks for watching!

Background

I made a small small application in WPF that has a grid layout consisting of one column and two rows. The top row contains a simple label for the title, and the bottom row contains a wrapper that is dynamically populated with image thumbnails at run time. Here is the XAML:

<Window x:Class="HTNavigator.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" WindowState="Maximized" WindowStyle="None">
    <Window.Background>
        <ImageBrush ImageSource="/HTNavigator;component/Images/HNBG.jpg" />
    </Window.Background>
    <Grid >
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="75"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>  
        <StackPanel Grid.Column="0" Grid.Row="0" Height="50" HorizontalAlignment="Left" Margin="30,10,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" FlowDirection="LeftToRight" Orientation="Horizontal" >
            <Label Content="Home Navigator v0.1" FontFamily="Tahoma" FontSize="18" FontWeight="Bold" Foreground="White" />
            <Button Content="Close" Height="50" Click="Button_Click"></Button>
        </StackPanel>
        <ScrollViewer Grid.Row="1" Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
            <WrapPanel HorizontalAlignment="Center" Name="spContainer" VerticalAlignment="Top" ClipToBounds="True"></WrapPanel>
        </ScrollViewer>
    </Grid>
</Window>

Problem

The scroll bar is not displayed, and the mouse-wheel scroll also does not work. I initially did not use a grid layout, and this time this part of XAML behaved as expected:

<ScrollViewer Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
            <WrapPanel HorizontalAlignment="Center" Name="spContainer" VerticalAlignment="Top"               ClipToBounds="True" ItemHeight="Auto"> </WrapPanel>
</ScrollViewer>

Now everything is correct, but I do not get my vertical scroll ability (I don't need horizontal scroll).

Any thoughts?

Thank!

Matt

+5
source share
1 answer

, , WrapPanel, Auto, . - WrapPanel *. , StackPanel.

" , " Grid.Row. .

+3

All Articles