[英]WPF Expander Not Expanding
I'd like to create a custom WPF accordion-like control without using WPF toolkit... After some searching it seems like the best approach would be to use an Expander... so I wanted to just see if I could get some sort of basic functionality like getting a row to expand upward to show some content when it is expanded and then to have it collapse and hide that content. 我想创建一个不使用WPF工具包的自定义WPF类手风琴控件。经过一番搜索,似乎最好的方法是使用Expander ...,所以我想看看是否能得到某种效果基本功能,例如使行向上扩展以在扩展时显示某些内容,然后使其折叠并隐藏该内容。 It seems like it should be pretty straight-forward but my expander never expands.
看起来应该很简单,但是我的扩展器永远不会扩展。 Here's my basic example:
这是我的基本示例:
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="215"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Expander Grid.Row="3" Grid.ColumnSpan="2" Header="More Options" ExpandDirection="Down" Background="Red" IsExpanded="False">
<StackPanel Height="300">
<CheckBox Margin="4" Content="Option 1" />
<CheckBox Margin="4" Content="Option 2" />
<CheckBox Margin="4" Content="Option 3" />
</StackPanel>
</Expander>
</Grid>
Update your RowDefinitions
. 更新您的
RowDefinitions
。 Currently, the Row
that the Expander
is in is hard-coded to have a Height
of 24. Make it Auto
. 当前,
Expander
所在的Row
的硬编码Height
为24。使其为Auto
。
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.