Setting the Template property on a UserControl is not supported.

Topics: Prism v4 - Silverlight 4
Oct 26, 2010 at 9:08 PM

I know the code causing this but I'm not sure exactly why.  All I know is it's starting to happen after I've integreated Prism 4.0 into my application.  In particular regions.  Again, I'm not pointing any fingers but I've posted this over on the Silverlight forum with zero responses.

It happens when I try to set an Image to a button.

<Button x:Name="BtnBack" HorizontalAlignment="Right" Command="{Binding CloseTruckDetailCommand}" >
                    <Image Source="EyeCue.Common;component/Assets/Images/Editor.png" Width="15" Height="15"/>

If I remve this portion, <Image Source="EyeCue.Common;component/Assets/Images/Editor.png" Width="15" Height="15"/> there are no problems.  However when I add it, silverlight throughs the following runtime error in a popup.

Line: 61
Error: Unhandled Error in Silverlight Application
Code: 4011   
Category: ManagedRuntimeError      
Message: Setting the Template property on a UserControl is not supported.    

In this particular case, there are I have a region loaded inside another region.  The button is on a page and is directly inside a grid.  Of course if I put it in a stackpanel or whatever I get the exception.

Also, it's not just the Button control.  If I use some other 3rd party controls I'm starting to see this. 

Additionaly we use a map control to map coordinates via images and it's throwing the exception now.

Google hasn't turned up much and the error itself doesn't make much sense. 

Any ideas?

Oct 28, 2010 at 7:58 PM


Based on the following forum thread if I am not wrong you solved this issue:

Message: Setting the Template property on a UserControl is not supported

Is my assumption right?

Fernando Antivero

Oct 28, 2010 at 8:06 PM
Edited Oct 28, 2010 at 8:13 PM

Thank you Fantivero for posting.  I was trying to find this and wasn't having any luck.

Yes I did resolve it.  I had switched to Prism and that included using the code for PopupRegions.  The popup regions in the app were using ChildWindows and I changed them all to UserControls.  The target type on the Style I changed to UserControl but inside it was a setter for Template.  (I took over this app and the themes were created a while ago.)

It was hard to track down because it didn't surface for a while and what made it come about didn't make sense.