5
votes

Hi and thanks for looking!

Background

I have made a simple little app in WPF that has a grid layout consisting of one column and two rows. The top row holds a simple label for the header, and the bottom row holds a wrappanel that is dynamically populated with image thumbnails at runtime. 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 scrollbar does not show and mouse-wheel scrolling also does not work. I originally did not use the grid layout, and at that this time this portion of the 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 lays out properly, but I don't get my vertical scroll ability (I do not want horizontal scroll).

Any thoughts?

Thanks!

Matt

1

1 Answers

5
votes

I know it is New Years Eve but you have nothing in the WrapPanel and you have the row height to Auto so it will grow for content. Put something in the WrapPanel and set the height to *. And take the Column off the Label that is inside a StackPanel.

In your example of "before you had a Grid" there is a Grid.Row. Happy New Year.