【问题标题】:WPF Xaml scrollviewer around Grid in GridWPF Xaml scrollviewer 在 Grid 中围绕 Grid
【发布时间】:2015-01-19 14:59:46
【问题描述】:

我在网格中有一个网格

<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>

我将滚动查看器设置在内部网格周围,但我希望它围绕外部网格。 问题是我的垂直滚动条在侧面的内容上方,并且还添加了水平滚动条。

【问题讨论】:

    标签: wpf xaml grid scrollviewer


    【解决方案1】:

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

    ,但我找到了一个对其他人有效的解决方案。

    Scrollviewer 和外部网格需要 width 属性而不是外部网格。 外层Grid需要Style(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>
    

    【讨论】:

    • 我遇到了多行文本框的问题,所以我还需要为外部网格添加宽度属性。 (文本框不可见)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多