Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Titled Border

Tags:

c#

wpf

xaml

Is there an equivalent in WPF to the Titled Borders that exists in Java's Swing framework? Below is a link that contains a screenshot of what I am looking for, and some very poor ASCII art.

http://www.java2s.com/Code/Java/Swing-JFC/TitledBorder.htm

-------TITLE--------
|                  |
|                  | 
|                  |
|__________________|

Thanks.

like image 285
Steve Avatar asked Jul 19 '10 13:07

Steve


2 Answers

What you're after is called a "GroupBox" in Windows speak.

I've found this example of how to use it on C# Corner:

<Window x:Class="GroupBoxSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <GroupBox Margin="10,10,10,10" FontSize="16" FontWeight="Bold"
                  Background="LightGray">
            <GroupBox.Header>               
               Mindcracker Network
            </GroupBox.Header>
           
            <TextBlock FontSize="12" FontWeight="Regular">
                This is a group box control content.               
            </TextBlock>            
        </GroupBox>
    </Grid>
</Window>

A GroupBox can only contain one direct child, so if you want several sub controls you'll have to wrap them in a Grid, a Panel, or a ContentControl.

There's more information on the GroupBox at the MSDN, it's Class Page and How to Style it.

If you want the header text to be anything other than left aligned then you'll need to create your own style (as outlined in this answer.

like image 186
ChrisF Avatar answered Nov 14 '22 17:11

ChrisF


In WPF this would be a GroupBox which in a container control that has a border and a header.

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

Here a GroupBox has a header\title of "Employee Data" and contains other controls.

http://i.msdn.microsoft.com/dynimg/IC79468.jpg

like image 39
Tim Lloyd Avatar answered Nov 14 '22 18:11

Tim Lloyd