WPF Expander 在网格行后面展开

发布于 2024-10-10 06:00:38 字数 1698 浏览 3 评论 0原文

我在网格行中有扩展器控件。我通过点击扩展器按钮来更改扩展器尺寸,以最大化扩展器尺寸。在折叠状态下,我最小化了扩展器的尺寸。问题是扩展器在网格行下方扩展。 有没有办法让扩展器在任何控件之上扩展?

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



    }

I have expander control in grid row. And I change the expander size on the expander button click to maximize the expander size. And on the collapse status I minimize the expander size. The problem is the expander expands under the grid row.
Is there is any way to make the expander expand on top of any control?

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



    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2024-10-17 06:00:38

这是因为您已经为网格控件设置了 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 教程 有关如何设置网格面板的行和列的更多详细信息

This is because you have set Grid.RowDefinition for you Grid control and didnt set the Grid.Row property for child controls

if not required remove the below code in you xaml

<Grid.RowDefinitions>
    <RowDefinition Height="199*" />
    <RowDefinition Height="175*" />
</Grid.RowDefinitions>

or

Add Grid.RowSpan property for your expander

<Expander Grid.RowSpan="2" Name="exp" Expanded="exp_Expanded"...

You can check WPF Tutorial for Grid Panel for more details on how to rows and columns for Grid Panel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文