Home > Silverlight > GroupBox

GroupBox

Here is a sample template for groupbox in silverlight (mostly from groupbox in WPF)
you can download the source here

Categories: Silverlight
  1. April 14, 2008 at 3:31 am | #1

    Hello,

    I think the spacing before text “Options” in groupbox looks a lit bit far…

  2. lee
    April 14, 2008 at 12:24 pm | #2

    Hi,
    The template from WPF doesnt seem to work as it does in WPF, if you notice the right hand top BorderThickness is bit wider than the rest. not sure why it is doing that. playing around with the column widths in the Grid in the Template would help

  3. Earnie
    June 25, 2008 at 2:21 pm | #3

    Hi,

    Thanks for the control, great work. I was having a problem in Firefox getting it to render the border and header (didn’t try IE). The border and header weren’t showing only the content. I added the following ctor to match your other controls and it worked just fine.

    public GroupBox()
    {
    DefaultStyleKey = typeof(GroupBox);
    }

  4. lee
    June 25, 2008 at 2:28 pm | #4

    yes, we need to do that as that is breaking change in beta2

  5. DRB
    September 25, 2008 at 3:55 am | #5

    I had to comment out BorderBrush and BorderBrushProperty to get this to work with latest Silverlight 2.0.

  6. lee
    September 25, 2008 at 8:44 am | #6

    Thanks for the comment. I did not get a chance to update this to beta2. This is very helpful

  7. tanusree
    November 5, 2008 at 10:18 am | #7

    Hi,
    This is very good & useful article.
    But this GroupBox is not working under DataTemplate.

    Is there any way to add an eventhandler to this GroupBox

    grp_Target(object sender, DataTransferEventArgs e) will e defined in my C# file.

    Thanks

  8. tanusree
    November 5, 2008 at 10:21 am | #8

    This groupBox is not working under DataTemplate.

    ——

  9. lee
    November 5, 2008 at 10:33 am | #9

    I am not sure what you meant. did you make the necessary changes to work in the released version of silverlight, like creating a folder called themes and moving the generic.xaml file into that folder?

  10. Ak
    November 11, 2008 at 2:45 am | #10

    When i use it in Silverlight RC0, I can only see the radiobutton, but groupbox.

    • lee
      February 9, 2009 at 10:00 am | #11

      Hi AK,
      Name the 2 border elements in generic.xaml border and border1 for ex

      Add code to groupbox.cs similar to the following
      In the constructor
      add an eventhandler
      IsEnabledChanged += new DependencyPropertyChangedEventHandler(GroupBox_IsEnabledChanged);
      declare 2 variables in the class as following
      Border b;
      Border b1;
      //event handler
      void GroupBox_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
      {
      b.BorderBrush = new SolidColorBrush(Colors.Magenta);
      b1.BorderBrush = new SolidColorBrush(Colors.Magenta);
      }

      public override void OnApplyTemplate()
      {
      base.OnApplyTemplate();
      b = GetTemplateChild(“border”) as Border;
      b1 = GetTemplateChild(“border1″) as Border;
      }

  11. lee
    November 11, 2008 at 9:18 am | #12

    looks like template is not being applied. did you create a Themes folder and move generic.xaml into that?

  12. lee
    November 11, 2008 at 10:19 am | #13

    for it to work in RTM

    1. create a folder called themes and move generic.xaml into that

    2. replace ContentPresenter with ContentControl in generic.xaml

    3. Add the following constructor to groupbox.cs
    public GroupBox()
    {

    DefaultStyleKey = typeof(GroupBox);

    }

  13. Ak
    February 9, 2009 at 5:39 am | #14

    Hi, lee
    I find that if i set the groupbox’s isEnabled property to false,
    the Header’s color is still black.
    Do you have any solutions to change the color to gray when the isEnabled is set to false?

    Thanks

  14. February 13, 2009 at 2:29 pm | #15

    Hi I’ve tried you control but it gives me an error “Object reference not set to an instance of an object.” at this line: HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;

    I’m using it in the latest version of silverlight 2.0

  15. lee
    February 13, 2009 at 3:47 pm | #16

    I am thinking, Template is not being applied.

    did you do this
    for it to work in RTM

    1. create a folder called themes and move generic.xaml into that

    2. replace ContentPresenter with ContentControl in generic.xaml

    3. Add the following constructor to groupbox.cs
    public GroupBox()
    {

    DefaultStyleKey = typeof(GroupBox);

    }

  16. February 16, 2009 at 7:09 am | #17

    It doesn’t work i have the same error, but if i comment that line “HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;” it show’s the content in the groupbox but not the header.

    Mybe I have this error because all the files are in the same projject the generic.xaml and the coude behind file it’s no timported from a diffrent project like in your test sample.

  1. November 26, 2008 at 7:33 am | #1