C# WPF中的GroupBox只能包含一个元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1356036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GroupBox in WPF can only contain one element?
提问by Athiwat Chunlakhan
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).
似乎 GroupBox 只能包含一个元素,如果我放置多个元素,它将不会进入(或在混合中被删除)。
Is this by design or am I doing something wrong?
这是设计使然还是我做错了什么?
采纳答案by Luke Quinane
That sounds right to me. You'd need to put a Grid or Panel (StackPanel, WrapPanel, etc) as a child to define the layout.
这对我来说听起来很正确。您需要将 Grid 或 Panel(StackPanel、WrapPanel 等)作为子项来定义布局。
回答by mike
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.
您必须将项目:文本框拖入分组框,并且必须只有一个分组框。不能为每个线性坐标拖动多个组框以使其工作。一个页面上可以有多个分组框,但不能超过一列宽,否则您将被限制为只能将一个项目添加到分组框。
回答by Aharon Muallem
回答by Hassan Rahman
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.
是的,在 WPF 中 GroupBox 最多包含 1 个元素。您可以将 Grid 作为其子项并在 grid 中指定所需的组件。例如 1 使用 Grid 在 GroupBox 中放置了两个按钮。
Document Outline is shown below:
文档大纲如下所示:
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>