GroupBox Example

GroupBox is pretty straightforward. There is one important extra method ApplyGroupBoxStrategyToRemoveExtraWhiteBorders which removes a pesky white border around the GroupBox.

Here is an example of creating a GroupBox with its Header:

GroupBox gpb = new GroupBox();
gpb.Initialize(349D, 405.0D, ContainerType.ContentControlPanel, 4, 3);

//Add Header
TextBlock tlb1 = new TextBlock(new Run("Vacation Destinations"));
tlb1.Background = Brushes.WhiteSmoke;
            
FontSettings fs1 = FontExt.CreateFont("Arial", 15D, FontWeights.Bold, FontStyles.Normal);
FontExt.ApplyFontSettings(fs1, tlb1);
           
 gpb.Header = tlb1;
gpb.BorderBrush = Brushes.Green;
gpb.BorderThickness = new Thickness(5);
gpb.Padding = new Thickness(7,5, 5, 7);

gpb.ApplyGroupBoxStrategyToRemoveExtraWhiteBorders(10);

You could also optionally and readily abstract away the creation of the Header into a static method like this:

public static void CreateGroupBoxHeader(this GroupBox grpbx, string headerTitle, Brush headerBackground, Brush foreground, string titleFont, double titleFontSize, FontWeight titleFontWeight, FontStyle titleFontStyle, Brush borderBrush, Thickness borderThickness)
{
            Label titleLabel = new Label();
            titleLabel.Content = headerTitle;
            titleLabel.Background = headerBackground;
            titleLabel.Foreground = foreground;
            FontSettings fontSettings = FontExt.CreateFont(titleFont, titleFontSize, titleFontWeight, titleFontStyle);
            FontExt.ApplyFontSettings(fontSettings, titleLabel);
            grpbx.Header = titleLabel;
            grpbx.BorderBrush = borderBrush;
            grpbx.BorderThickness = borderThickness;
}

Last edited Mar 28, 2014 at 6:06 AM by stagathome0069, version 2

Comments

No comments yet.