Steps for creating your UserControl from your derived class

|  Posted: February 28, 2010  |  Categories: General Technical

When you start learning Silverlight or even to some extend on a medium size project, you’ll be fine with deriving your user controls directly from System.Windows.Controls.UserControl. But soon you’ll be in a situation to derive your user controls from your own custom user control to keep something consistent. Here are the steps

Step 1:

Create a custom user control derived from System.Windows.Controls.UserControl. Ex:

public class EnvironmentAwareUserControl : UserControl

{

public EnvironmentSettings EnvironmentSettings { get; set; }

}

Step 2:

Once you added a new Silverlight User Control to your project, change it to

from:

public partial class SilverlightControl1 : UserControl

to:

public partial class SilverlightControl1 : EnvironmentAwareUserControl

Step 3:

This is the confusing bit (or the way Silverlight/WPF works). You need the change the XAML as well to reflect that you are deriving it from a custom control.

from :

<UserControl x:Class=”Test.UI.SilverlightControl1″

to:

<EnvironmentAwareUserControl x:Class=”Test.UI.SilverlightControl1″

or

<local:EnvironmentAwareUserControl x:Class=”Test.UI.SilverlightControl1″
xmlns:local=”clr-namespace:Test.UI.Controls”

depending on your namespace declaration.

Common Error message you’ll see when you try to figure out this “Partial declarations of must not specify different base classes

Nandri!

Saravana

Author: Saravana Kumar

Saravana Kumar is the Founder and CTO of BizTalk360, an enterprise software that acts as an all-in-one solution for better administration, operation, support and monitoring of Microsoft BizTalk Server environments.

Back to Top