Skip to main content

Microsoft Silverlight

Answered Question Using a Custom Panel in a ControlTemplate causes a Catastrophic failureRSS Feed

(0)

Marcus417
Marcus417

Member

Member

0 points

3 Posts

Using a Custom Panel in a ControlTemplate causes a Catastrophic failure

Using a custom Panel in a ControlTemplate causes a System.Exception: "Catastrophic failure" ( No significant error code, message or call stack ).

Here is a simple setup that reproduces the issue:

<UserControl x:Class="CustomPanelProblem.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomPanelProblem">
<Grid Background="Orange">
<Button Margin="5">
<Button.Template>
<ControlTemplate TargetType="Button">
<local:CustomPanel Background="HotPink" />
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</UserControl>

Code for CustomPanel is:

public class CustomPanel: StackPanel
{
}

Note: Replacing the CustomPanel by a StackPanel makes the program work without exceptions.
Note2: I have originally tried starting with Panel as a base class along with custom measuring/arranging (with same result).

Any ideas on why this exception is launched or on any workarounds?

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Re: Using a Custom Panel in a ControlTemplate causes a Catastrophic failure

Should work but all depends on your implementation of the Panel. Can you share it with us?

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

Marcus417
Marcus417

Member

Member

0 points

3 Posts

Re: Using a Custom Panel in a ControlTemplate causes a Catastrophic failure

Hi Shawn,

  As indicated, the panel implementation is kept to the minimum:
 
public class CustomPanel: StackPanel
{
}

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Answered Question

Re: Re: Using a Custom Panel in a ControlTemplate causes a Catastrophic failure

Sorry, didn't see that.

 When I test your code with the empty CustomPanel it works for me.  Is there any other code anywhere?

 This is my XAML:

<UserControl x:Class="SilverlightApplication13.Page"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:SilverlightApplication13">
  <Grid Background="Orange">
    <Button Margin="5">
      <Button.Template>
        <ControlTemplate TargetType="Button">
          <local:CustomPanel Background="HotPink" />
        </ControlTemplate>
      </Button.Template>
    </Button>
  </Grid>
</UserControl>

And my CustomPanel:

  public class CustomPanel : StackPanel
  {
  }

Pasted my code in case its differetn in some way.  But it works for me.

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

Marcus417
Marcus417

Member

Member

0 points

3 Posts

Re: Re: Using a Custom Panel in a ControlTemplate causes a Catastrophic failure

Hi Shawn,

   After you mentionned it was all working fine on your side, I went back for intensive testing both on my primary machine and several other computers.

   While I have not found the root of the issue, I am now able to run the code as posted, but in a separate newly created project. I will try to investigate further to determine why my test project caused this issue and report on my findings.

   Thank you for your help.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities