【问题标题】:GridSplitter resize nextGridSplitter 下一个调整大小
【发布时间】:2016-08-23 05:57:06
【问题描述】:

看来我不能使用GridSplitter 来调整下一个项目的大小。这是 xaml:

<Grid>
    <!-- this works -->
    <Grid Background="Gray" HorizontalAlignment="Left">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        <GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
    </Grid>
    <!-- this doesn't -->
    <Grid Background="Gray" HorizontalAlignment="Right">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="100" />
        </Grid.ColumnDefinitions>
        <GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
    </Grid>
</Grid>

和演示:

注意左边的Grid 可以调整大小,而右边的有一些问题。你可以自己尝试给 xaml 看看我的意思。

我应该怎么做才能使下一个项调整大小起作用?

【问题讨论】:

    标签: c# wpf xaml layout gridsplitter


    【解决方案1】:

    我通过更改 ColumnDefinition Width 使其工作

    <Grid>
        <Grid Background="Gray" HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
        </Grid>
        <Grid Background="Gray" HorizontalAlignment="Right">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="100" />
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
        </Grid>
    </Grid>
    

    还有一个我更喜欢的变体:

    <Grid>
        <Grid Background="Gray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="100" />
            </Grid.ColumnDefinitions>
    
            <GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
    
            <Border Grid.Column="2" Background="Gold"/>
    
            <GridSplitter Grid.Column="3" Width="10" ResizeBehavior="PreviousAndNext" />
        </Grid>
    </Grid>
    

    【讨论】:

    • 你有没有解释为什么* 有效而auto 也有效但只是在一个方向?我的问题是在不可调整大小的列中有 optional 内容,这就是为什么它必须是auto。不确定它是否适用于 *,请稍等。
    • @Sinatr,我只能猜测这是拆分器的内部逻辑。由于网格具有左右水平对齐方式,* 变为 auto
    猜你喜欢
    • 2016-05-29
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多