请参考以下图片,这是我所说的静态框:
我不确定这是否是它的正式名称。
该框应能够容纳任意子控件(面板等)。
![enter image description here](https://istack.dev59.com/0NLC5.gif)
该框应能够容纳任意子控件(面板等)。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<GroupBox Header="Test 1">
<StackPanel Margin="6">
<RadioButton x:Name="option1RadioButton" Content="Option 1" />
<RadioButton x:Name="option2RadioButton" Content="Option 2" />
<RadioButton x:Name="option3RadioButton" Content="Option 3" />
</StackPanel>
</GroupBox>
</Window>
酷炫功能
与标准的Win32 group box相比,WPF GroupBox更加强大。您不仅可以在标题中设置文本,还可以设置任何类型的内容,例如图片或其他控件:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<GroupBox>
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Button Content="Test 1" />
<Label Content="Test 2" />
<Button Content="Test 3" />
</StackPanel>
</GroupBox.Header>
<StackPanel Margin="6">
<RadioButton x:Name="option1RadioButton" Content="Option 1" />
<RadioButton x:Name="option2RadioButton" Content="Option 2" />
<RadioButton x:Name="option3RadioButton" Content="Option 3" />
</StackPanel>
</GroupBox>
</Window>
是的,在WinForms/WPF世界中,这被称为GroupBox。
要设置其中的文本,请设置Header
属性:
<GroupBox Header="Some Text">
<Grid>
<!--Other Controls-->
</Grid>
</GroupBox>