GridSplitter接下来调整大小

时间:2016-04-28 12:48:01

标签: c# wpf xaml layout gridsplitter

我似乎无法使用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看看我的意思。

如何让下一个项目调整大小?

1 个答案:

答案 0 :(得分: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>