我在网格行中有扩展控件。然后我在扩展器按钮上单击更改扩展器大小以最大化扩展器大小。在崩溃状态下,我最小化扩展器大小。问题是扩展器在网格行下扩展。 有没有办法让扩展器扩展到任何控件之上?
<Grid AllowDrop="False">
<Grid.RowDefinitions>
<RowDefinition Height="199*" />
<RowDefinition Height="175*" />
</Grid.RowDefinitions>
<Grid Height="60" HorizontalAlignment="Left" Margin="21,26,0,0" Name="grid1" VerticalAlignment="Top" Width="550" Background="#FFE59E9E">
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="62,113,0,0" Name="label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="130,115,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Background="#FF2B1313" />
</Grid>
<Expander Name="exp" Expanded="exp_Expanded" Background="#FF3383A7" BorderThickness="4" BorderBrush="{x:Null}" FlowDirection="LeftToRight" Collapsed="exp_Collapsed" ExpandDirection="Left" Height="49" VerticalAlignment="Top" HorizontalAlignment="Right" Width="602" Margin="0,139,237,0">
<DataGrid AutoGenerateColumns="False" Height="105" Name="dataGrid1" Width="200" HorizontalContentAlignment="Center" VerticalAlignment="Center" />
</Expander>
</Grid>
private void exp_Expanded(object sender, RoutedEventArgs e)
{
var exp = (Expander) sender;
//grid1.Width = 550;
// grid1.Height = 40;
exp.Width = 602;
exp.Height = 300;
}
private void exp_Collapsed(object sender, RoutedEventArgs e)
{
var exp = (Expander)sender;
// grid1.Height = 500;
exp.Width = 602;
exp.Height = 49;
}
答案 0 :(得分:2)
这是因为您为网格控件设置了Grid.RowDefinition
并且没有为子控件设置Grid.Row
属性
如果不需要,请删除xaml中的以下代码
<Grid.RowDefinitions>
<RowDefinition Height="199*" />
<RowDefinition Height="175*" />
</Grid.RowDefinitions>
或
为扩展程序添加Grid.RowSpan
属性
<Expander Grid.RowSpan="2" Name="exp" Expanded="exp_Expanded"...
您可以查看WPF Tutorial for Grid Panel以获取有关网格面板
的行和列的更多详细信息