WPF Xaml滚动查看器网格中的网格

时间:2015-01-19 14:59:46

标签: wpf xaml grid scrollviewer

我在Grid中有一个Grid

<Grid Style="{StaticResource GridMinWidthEditStyle}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Text="xxx" Style="xxx"/>
    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" PanningMode="VerticalOnly">
        <Grid  Background="{StaticResource LightBackground}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
        </Grid>
    </ScrollViewer>
</Grid>

我在内部网格周围设置了我的scrollviewer,但是我希望它围绕外部网格。 问题是我的垂直滚动条位于我侧面的内容上,并且还添加了一个水平滚动条。

1 个答案:

答案 0 :(得分:3)

滚动条在右侧再次出现我的内容

,但我找到了一个可以解决问题的解决方案。

Scrollviewer和外部网格需要width属性而不是外部网格。 外部网格需要样式(MinWidth)

<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" PanningMode="VerticalOnly" 
    Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
    <Grid Style="{StaticResource GridMinWidthEditStyle}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Text="xxx" Style="xxx"/>
        <Grid  Background="{StaticResource LightBackground}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
        </Grid>
    </Grid>
</ScrollViewer>