我正在尝试创建一种样式,通过将内容嵌入到GridSplitter的网格中,自动使我的所有Expanders可调整大小。
<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绑定到扩展器内容的MinHeight。
(注意,花哨的颜色只是为了看看是什么......)
答案 0 :(得分:0)
我不确定你需要哪种dinamycally,如果这解决了你的问题:
<Grid.RowDefinitions>
<RowDefinition x:Name="GridRowDefinition" Height="Auto" MinHeight="20"/>
<RowDefinition x:Name="GridRowDefinition2" Height="Auto" MinHeight="20"/>
</Grid.RowDefinitions>
以风格
<Setter.Value>
<DataTemplate>
<Grid Margin="0" Background="Red">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="{Binding MinHeight, ElementName=GridRowDefinition}"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<ContentControl Content="{Binding}" MinHeight="{Binding MinHeight, ElementName=GridRowDefinition2}"/>
<GridSplitter Grid.Row="1" Height="5" Background="Green"
HorizontalAlignment="Stretch"
ResizeBehavior="PreviousAndCurrent"/>
</Grid>
</DataTemplate>
</Setter.Value>
因为如果在扩展器中添加边框,我不明白为什么要在扩展器中放置内容。我希望它有所帮助
答案 1 :(得分:0)
愚蠢的我:查看调试输出表明{Binding}
与内容无关(在本例中为Border)。因此,简单地在RowDefinition(在Style.DataTemplate内)上执行{Binding MinHeight}
具有完全所需的效果。
下一步:弄清楚如何记忆和恢复高度:)