在WPF表单中,我有一个扩展器,可以扩展到其他控件之上,例如按钮:
<Expander Grid.Row="0" Panel.ZIndex="99" Name="searchMenuExpander" Header="Search menu" FontWeight="Bold" HorizontalAlignment="Stretch" Margin="10,10,0,0" MinWidth="510" MinHeight="200" VerticalAlignment="Top" Foreground="MidnightBlue" Cursor="Arrow">
<Grid Background="White">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<TextBlock Text="Name" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20,10,0,0" Width="65" Height="20" Cursor="Arrow" />
<TextBox Name="nameSearchTextBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="115,10,0,0" Width="100" Height="20"/>
</Grid>
</Expander>
<Button Content="Button" Height="34" Width="85"/>
我的问题是扩展器后面的控件不再可以点击,即使展开器没有展开也是如此。怎么了?我怎么能摆脱这个错误?
答案 0 :(得分:0)
假设您的Grid
是Expander
和Button
的父亲,则需要将按钮放在另一行。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Expander Grid.Row="0">
</Expander>
<Button Grid.Row="1" />
</Grid>
通过将第一行(包含扩展器)的Height
设置为Auto
,可确保在扩展器未展开时将其最小化(仅扩展器的标头部分)将占据空间。)
答案 1 :(得分:-1)
我发现了一种方法,代码背后。我将Expander
放在Canvas
中,然后我添加了Expander
两个事件:
Expanded="searchMenuExpander_Expanded"
和Collapsed="searchMenuExpander_Collapsed"
其定义为:
private void searchMenuExpander_Expanded(object sender, RoutedEventArgs e)
{
Canvas.SetZIndex(searchMenuCanvas, 99);
}
private void searchMenuExpander_Collapsed(object sender, RoutedEventArgs e)
{
Canvas.SetZIndex(searchMenuCanvas, 0);
}