0

我在一个窗口中有 3 个扩展器,我想知道是否有办法拥有它,这样如果我打开了扩展器 2 和 3,但没有打开 1,它只会拉伸这 2 个。目前正在平等地拉伸所有三个。此外,当它们关闭时,内容会关闭,但列保持与打开时相同的宽度。

让它们仅在展开时拉伸并在折叠时返回到 10 像素宽的小尺寸的最佳方法是什么?

4

1 回答 1

4

You could set Triggers on the ColumnDefinitions to set the Width to Fixed when the Expander is closed and set to proportional when the Expander is open.

Example:

     <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition>
                <ColumnDefinition.Style>
                    <Style TargetType="ColumnDefinition">
                        <Setter Property="Width" Value="20" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded, ElementName=expander1}" Value="True">
                                <Setter Property="Width" Value="20*" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ColumnDefinition.Style>
            </ColumnDefinition>
            <ColumnDefinition>
                <ColumnDefinition.Style>
                    <Style TargetType="ColumnDefinition">
                        <Setter Property="Width" Value="20" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded, ElementName=expander2}" Value="True">
                                <Setter Property="Width" Value="20*" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ColumnDefinition.Style>
            </ColumnDefinition>
            <ColumnDefinition>
                <ColumnDefinition.Style>
                    <Style TargetType="ColumnDefinition">
                        <Setter Property="Width" Value="20" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded, ElementName=expander3}" Value="True">
                                <Setter Property="Width" Value="20*" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ColumnDefinition.Style>
            </ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Expander Name="expander1" Grid.Column="0" Header="Expander1" />
        <Expander Name="expander2" Grid.Column="1" Header="Expander2" />
        <Expander Name="expander3" Grid.Column="2" Header="Expander3" />
    </Grid>

Result:

enter image description here enter image description here

enter image description here enter image description here

于 2013-03-26T21:22:49.963 回答