Add scrolling to a StackPanel in a Grid Column

488 views Asked by At

currently I try to add a vertical Scrollbar to my StackPanel by subordinate the StackPanel to my ScrollViewer. But with this "Solution" the content in my StackPanel dissapears and neither i have the Scrollbar.

My XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="12*"/>
        <RowDefinition Height="77*"/>
        <RowDefinition Height="207*"/>
        <RowDefinition Height="23*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="12*"/>
        <ColumnDefinition Width="436*"/>
        <ColumnDefinition Width="153"/>
    </Grid.ColumnDefinitions>

    <ListView x:Name="lv_Addresses" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2">
        <ListView.View>
            <GridView>
                <GridViewColumn/>
            </GridView>
        </ListView.View>
    </ListView>

    <StackPanel Grid.Column="2" Grid.Row="1" Margin="0,0,0,10">
        <Label     x:Name="lbl_Search"    Margin="3,0,12,0" Content="Suche"/>
        <TextBox   x:Name="tbx_Search"    Margin="6,0,12,0"/>
        <Rectangle x:Name="rct_Separator" Margin="0,18,0,0" HorizontalAlignment="Stretch" Fill="Gray" Height="3"/>
    </StackPanel>

    <ScrollViewer VerticalScrollBarVisibility="Visible">
        <StackPanel Grid.Column="2" Grid.Row="2" Margin="0,0,0,10" >
            <Label     x:Name="lbl_SName"     Margin="3,0,12,0" Content="Nachname"/>
            <TextBox   x:Name="tbx_SName"     Margin="6,0,12,0"/>
            <Label     x:Name="lbl_FName"     Margin="3,0,12,0" Content="Vorname"/>
            <TextBox   x:Name="tbx_FName"     Margin="6,0,12,0"/>
            <Label     x:Name="lbl_Plz"       Margin="3,0,12,0" Content="Postleitzahl"/>
            <TextBox   x:Name="tbx_Plz"       Margin="6,0,12,0"/>
            <Label     x:Name="lbl_Location"  Margin="3,0,12,0" Content="Ort"/>
            <TextBox   x:Name="tbx_Location"  Margin="6,0,12,0"/>
            <Label     x:Name="lbl_Street"    Margin="3,0,12,0" Content="Straße"/>
            <TextBox   x:Name="tbx_Street"    Margin="6,0,12,0"/>
        </StackPanel>
    </ScrollViewer>
</Grid>
1

There are 1 answers

0
ASh On

after you put StackPanel into ScrollViewer, set Grid.Column="2" Grid.Row="2" on ScrollViewer. Otherwise it goes into (0; 0) Grid cell