Implementing a Base Silverlight UserControl
Last post 05-13-2008 8:25 AM by Puts. 3 replies.
Sort Posts:
05-09-2008 9:02 AM
Implementing a Base Silverlight UserControl

Hello, i have found some wierdness when trying to inherit a base silverlight user control much as i would reference a base page in asp.net.  When changing the base class of a page it properly reflects the base class in the mostly unseen .g partial class that is created.  When i do the same with a silverlight control it does not change the .g file.  I was able to manually go in and set the base class in the g file and it worked correctly.  When i choose Build it retains the base class.  If i choose Rebuild it resets the g file to a usercontrol base class and throws a compiler error saying the partial classes do not inherit the same base.  The same also happens if i make any changes to the page im working on.  If write a new element into the xaml and save the file it will reset the base class in the generated file.  This is basically causing me that every time i make a change i have to view all files, open up the g file and fix the base class again.  Is this a bug or is it never intended for a silverlight page to implement a base page?

Puts

Joined on 05-09-2008
Posts 15
05-12-2008 10:17 PM
Re: Implementing a Base Silverlight UserControl

Beta 1 does not allow the user to subclass UserControl. This has been fixed in Beta 2.

- Tom

Tom Taylor | Microsoft Silverlight

tomtaylormsft

Joined on 05-01-2007
Posts 64
05-12-2008 11:11 PM
Marked as Answer
Re: Implementing a Base Silverlight UserControl

Hello Puts,

If I understand you correctly, you can to inherit Page.cs from Base class, right? I have one important thing to ask you.  Does your basepage or control has XAML? If yes, you won't be able to do with beta1. If no, you can do that.

Please check-out this sample. http://michaelsync.net/2008/03/24/silverlight-2-beta1-user-control-inheritance 

Hope it helps. 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlsync

Joined on 09-16-2005
Singapore
Posts 2,021
05-13-2008 8:25 AM
Re: Implementing a Base Silverlight UserControl

Michael, i am currently not using any xaml in the base control.  It is mainly there to provide an automatic base mechanism for pages inheritting it to be able to sync up with a web service caching system im experimenting with.  I see in the example that instead of direct inheritence it puts the base page as a control to the page, which is fine for the moment.  Thanks for the help and i look forward to having direct inheritence supported in future releases.

 

Puts

Puts

Joined on 05-09-2008
Posts 15