NullReferenceException was thrown on "GroupBox" Object reference not set to an instance of an object." at SilverlightContrib.Controls.GroupBox.OnApplyTemplate()


Windows 7 x64
Visual Studio 2010
SilverlightContrib 2009.1
Silverlight 4 project
GroupBox added to tab item other than the first one in a tab control will produce the following exception in the xaml designer:
NullReferenceException was thrown on "GroupBox": [Line 0 Position 0]
An Unhandled Exception has occurred
Object reference not set to an instance of an object.
at SilverlightContrib.Controls.GroupBox.OnApplyTemplate()
at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
Also see http://programmerpayback.com/2008/11/26/silverlight-groupbox-control/#comment-786


icnocop wrote Aug 21, 2010 at 4:30 AM

This only occurs if your root layout element is a <StackPanel />. If it is a <Grid /> then this error does not occur.

icnocop wrote Aug 21, 2010 at 4:35 AM

Actually, never mind; it still happens if you use a <Grid />

icnocop wrote Sep 1, 2010 at 2:11 AM

The fix is to update .\src\SilverlightContrib.Controls\GroupBox\GroupBox.cs:
public override void OnApplyTemplate()

        FullRect = GetTemplateChild("FullRect") as RectangleGeometry;
        HeaderRect = GetTemplateChild("HeaderRect") as RectangleGeometry;
        HeaderContainer = GetTemplateChild("HeaderContainer") as ContentControl;
        if (HeaderContainer != null)
            HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;

wrote Apr 6, 2011 at 1:06 PM

JoeBrockhaus wrote Oct 14, 2011 at 3:49 PM

this has been driving me up a wall for some time now, but i never took the time to track it down.
sometimes i'd just cut out the offending groupbox -- but a fix is much better!

any chance this will get merged into the codebase?

wrote Feb 14, 2013 at 4:03 AM