开发者

Does WPF have a "static box" control?

Please see this image for what I'm referring to as a static box:

Does WPF have a "static box" control?

I'm not sure if that is it's proper name.

The box should be able to ho开发者_如何学运维ld an arbitrary child control (panel etc.) inside.


In WPF, it is called a GroupBox

See the MSDN documentation for the control:

http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx

How to use it

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

Cool features

The WPF GroupBox is a bit more powerful than your standard Win32 group box. Instead of just being able to set text in the header, you can set any sort of content you want, such as images, or other controls:

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

Does WPF have a "static box" control?


Yep, that's called a GroupBox in WinForms/WPF world.

To set the text in it, set the Header property:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜