GroupBox

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

Advertisements

20 thoughts on “GroupBox

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

  2. 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);
    }

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

  4. 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?

    1. 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;
      }

  5. 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);

    }

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

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

  8. 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);

    }

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

  10. I’ve tried this groupbox in a tabcontrol and tabitem, it works if it’s in the first tabitem, but OnApplyTemplate raises a nullreference exception both runtime and VS Designer…

    What could be the cause and how to fix it???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s