1

我在网格行中有扩展器控件。我在扩展器按钮上更改扩展器大小,单击以最大化扩展器大小。在折叠状态下,我将扩展器尺寸最小化。问题是扩展器在网格行下展开。有什么方法可以使扩展器在任何控件之上扩展?

<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;



    }
4

1 回答 1

3

这是因为您已经Grid.RowDefinition为您设置了 Grid 控件并且没有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以获取有关如何为 Grid Panel 设置行和列的更多详细信息

于 2011-01-03T09:02:41.953 回答