WPF有静态框控件吗?

4
请参考以下图片,这是我所说的静态框: enter image description here 我不确定这是否是它的正式名称。
该框应能够容纳任意子控件(面板等)。
2个回答

5
在WPF中,它被称为GroupBox
请参阅该控件的MSDN文档: http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx 如何使用它
<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>

group box with custom header content


4

是的,在WinForms/WPF世界中,这被称为GroupBox。

要设置其中的文本,请设置Header属性:

<GroupBox Header="Some Text">
  <Grid>
     <!--Other Controls-->
  </Grid>
</GroupBox>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接