WPF中的GroupBox只能包含一个元素?

发布于 2024-08-03 05:09:35 字数 81 浏览 5 评论 0原文

看来 GroupBox 只能包含一个元素,如果我放置多个元素,它就不会进入其中(或在混合中被删除)。

这是设计使然还是我做错了什么?

It seem that GroupBox can only contain one element, if I place more than one it's won't go inside(or get deleted in blend).

Is this by design or am I doing something wrong?

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

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

发布评论

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

评论(4

迷迭香的记忆 2024-08-10 05:09:35

这对我来说听起来不错。您需要将网格或面板(StackPanel、WrapPanel 等)作为子项来定义布局。

That sounds right to me. You'd need to put a Grid or Panel (StackPanel, WrapPanel, etc) as a child to define the layout.

生生漫 2024-08-10 05:09:35

是的,在 WPF 中,GroupBox 最多包含 1 个元素。您可以将 Grid 作为其子项包含在内,并在网格中指定您所需的组件。例如 1 使用 Grid 在 GroupBox 中放置了两个按钮。

文档大纲如下所示:

文档大纲

代码如下:

<GroupBox
            Header="Read Sensor"
            HorizontalAlignment="Left"
            Margin="485,4,0,0"
            VerticalAlignment="Top"
            Height="188"
            Width="238">
            <Grid
                HorizontalAlignment="Left"
                Height="169"
                Margin="0,0,-13,-3"
                VerticalAlignment="Top"
                Width="229">
                <Button
                    x:Name="btnReadSensor1"
                    Content="Read Sensor 1"
                    HorizontalAlignment="Left"
                    Margin="10,91,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor1_Click" />
                <Button
                    x:Name="btnReadSensor2"
                    Content="Read Sensor 2"
                    HorizontalAlignment="Left"
                    Margin="10,64,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor2_Click" />
            </Grid>
</GroupBox>

Yes, in WPF the GroupBox will contain maximum of 1 element. You can include Grid as its child and in grid specify your desired components. For example 1 placed two buttons in GroupBox using Grid.

Document Outline is shown below:

Document Outline

Code is as follow:

<GroupBox
            Header="Read Sensor"
            HorizontalAlignment="Left"
            Margin="485,4,0,0"
            VerticalAlignment="Top"
            Height="188"
            Width="238">
            <Grid
                HorizontalAlignment="Left"
                Height="169"
                Margin="0,0,-13,-3"
                VerticalAlignment="Top"
                Width="229">
                <Button
                    x:Name="btnReadSensor1"
                    Content="Read Sensor 1"
                    HorizontalAlignment="Left"
                    Margin="10,91,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor1_Click" />
                <Button
                    x:Name="btnReadSensor2"
                    Content="Read Sensor 2"
                    HorizontalAlignment="Left"
                    Margin="10,64,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor2_Click" />
            </Grid>
</GroupBox>
明天过后 2024-08-10 05:09:35

好吧,真正的答案是因为 groupbox 继承自 HeaderedContentControl

看看这里
MSDN

Well the real answer is because groupbox inherits from HeaderedContentControl

Take a look here
MSDN

菩提树下叶撕阳。 2024-08-10 05:09:35

您必须将项目:文本框拖入组框,并且只能有一个组框。每个线性坐标无法拖动多个组框才能正常工作。页面上可以有多个组框,但宽度不能超过单列,否则您将受到限制,只能将单个项目添加到组框中。

You must drag the items: textbox INTO the groupbox and must only have a single groupbox. Cannot drag more than a single groupbox per linear coordinate for it to work. Can have multiple groupboxes on a page, but not more than a single column wide or you will be limited with only having a single item being added to the groupbox.

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