【发布时间】:2015-04-28 05:31:39
【问题描述】:
我正在尝试创建一种样式,通过将内容嵌入到带有 GridSplitter 的网格中,自动使我的所有扩展器可调整大小。
<Window.Resources>
<Style TargetType="Expander">
<Setter Property="Background" Value="Gold"/>
<Setter Property="FontSize" Value="17"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid Margin="0" Background="Red">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="{Binding ???}"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<ContentControl Content="{Binding}" MinHeight="{Binding ???}"/>
<GridSplitter Grid.Row="1" Height="5" Background="Green"
HorizontalAlignment="Stretch"
ResizeBehavior="PreviousAndCurrent"/>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander Grid.Row="0" IsExpanded="True" Header="Expander...">
<Border Background="Blue" MinHeight="200" BorderThickness="5" BorderBrush="Black"/>
</Expander>
<Expander Grid.Row="1" IsExpanded="True" Header="Expander...">
<Border Background="Blue" MinHeight="100" BorderThickness="5" BorderBrush="Black"/>
</Expander>
</Grid>
我想不通的是如何将样式内部的 RowDefinition(或 ContentControl)的 MinHeight 绑定到 Expander 的 Content 的 MinHeight。
(注意,花哨的颜色只是为了看看是什么......)
【问题讨论】: