将滚动添加到网格列中的StackPanel

时间:2017-11-30 14:47:18

标签: wpf xaml stackpanel wpfgrid

目前我尝试通过将StackPanel从属于我的ScrollViewer,将垂直滚动条添加到我的StackPanel。 但是使用这个“解决方案”,我的StackPanel中的内容消失了,而且我没有滚动条。

我的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 个答案:

答案 0 :(得分:0)

将StackPanel放入ScrollViewer后,在ScrollViewer上设置Grid.Column="2" Grid.Row="2"。否则它进入(0; 0)网格单元