EzhNotes

February 22, 2009

Subsclass UserControl in SilverLight

Filed under: Uncategorized — alexezh @ 9:30 pm

By default Expression creates custom controls derived from UserControls

partial class MyControl : UserControl
{
}

In order to derive from a different class you will have to change code in several places

Define new base class with required virtual methods. Do not make class abstract

public class MyUserControl : UserControl
{
public virtual void Foo() {;}
}

Change MyControl to use MyUserControl

partial class MyControl : UserControl
{
public override void Foo() {;}
}

Change XAML for MyControl to use

&ltMyUserControl x:Class=”MyControl”&gt
&lt/MyUserControl&gt

To make Blend happy, add following lines to AssemblyInfo.cs

// Make blend happy
using System.Windows.Markup;
[assembly: XmlnsDefinition(“http://schemas.microsoft.com/client/2007”, “YourNamespace”)]

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: