Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Using a Custom Panel in a ControlTemplate causes a Catastrophic failure
4 replies. Latest Post by Marcus417 on January 13, 2009.
(0)
Marcus417
Member
0 points
3 Posts
01-09-2009 11:55 AM |
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
Star
8320 points
1,546 Posts
01-09-2009 12:06 PM |
Should work but all depends on your implementation of the Panel. Can you share it with us?
01-09-2009 1:15 PM |
Hi Shawn, As indicated, the panel implementation is kept to the minimum: public class CustomPanel: StackPanel{}
01-09-2009 2:53 PM |
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.
01-13-2009 12:53 PM |
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.