Extending User Control in Silverlight 2 Beta 2

July 1, 2008 at 5:36 am | Posted in Silverlight 2 | Leave a comment
Tags: , , ,

There is a breaking change in Beta 2 for the way user control inheritance is implemented. In Beta 1 if you have created a base class which you want to extend in other pages it is done simply replacing the base class name with “<UserControl …. “ tag as “<BaseClass …”.
But this does not work in Beta 2. To solve this problem you need declare the namespace of your library and then include it as it was done in case of including in custom controls.

Suppose my base class is BaseRnd, which is just inheriting the UserControl class

namespace RnD
{
    public class BaseRnd : UserControl
    {      
   
}
}

Child Class inheriting the BaseRnd
namespace RnD
{
    public partial class TestPage : BaseRnd
    {
        public TestPage()
        {
            InitializeComponent();            
        }       
    }
}

<myBase:BaseRnd x:Class=”RnD.TestPage”
    xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation 
    xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml 
    xmlns:myBase=”clr-namespace:RnD
    Width=”400″ Height=”300″>

 

Change the closing tag as well.
Do this and it will start working
J

Check out my site www.silverlightchannel.com, just started adding some articles.

Blog at WordPress.com.
Entries and comments feeds.