Dec 07

The purpose of this post is to show you how to declare and use a specific user control in Silverlight. To do this I'll use a simple example of a Wizard page containing user control representing steps.

Here is the corresponding class diagram:

clip_image002

In our example each wizard step is a “UserControl” type “WizardControl” that is to say; it contains the method “Next” and “Previous” as defined in the interface “IWizardControl”.

How do I create it step by step?

Step 1: Create the base class

public class WizardControl : UserControl, IWizardControl
{
    public virtual void Next() { }
    public virtual void Previous() { }
}

Step 2: Initialization in XAML

<src:WizardControl x:Class="UserControlInheritance.WizardStep1"
    xmlns:src="clr-namespace:UserControlInheritance.Controls"
</src:WizardControl>

Step 3: in the code behind, we inherit WizardControl

public partial class WizardStep1 : UserControlInheritance.Controls.WizardControl
{
    public WizardStep1()
    {
        InitializeComponent();
    }

    public override void Next()
    {
        base.Next();
        MessageBox.Show(String.Format("Hello {0}", NameTextBox.Text));
    }

    public override void Previous()
    {
        base.Previous();
    }
}

Use of the user controls

And finally, as a result, we can create a wizard with a list of the different steps. Like this:

wizard = new List<WizardControl>()
{
	new WizardStep1(), 
	new WizardStep2()
};

WizardControl currentControl = contentControl.Content as WizardControl;
contentControl.Content = controls[currentIndex];

And here is the "visual" result:

clip_image004

Full source code here:

Tags:

Comments

Wendy Drivng Schools

Posted on Sunday, 4 July 2010 03:48

Nice post! Love to see more coming from you, I've read your stuff before.

luggage scales

Posted on Monday, 5 July 2010 18:45

To do this I'll use a simple example of a Wizard page containing user control representing steps.

CAROL

Posted on Monday, 19 July 2010 20:06

anyone has a demo version?

ronald napole

Posted on Monday, 19 July 2010 20:08

i'm going to send you tomorrow...
good luck Smile

Blog Literature

Posted on Thursday, 22 July 2010 16:57

I also want to download its demo version. Can you give me the url where i can download it?

idolreplicas

Posted on Saturday, 24 July 2010 00:01



I was very glad to discover this site on google.I wished to say thank you to you with regard to this superb article!! I definitelyliked every little bit of it and I've you bookmarked to check out new stuff you post.

Rico Relles

Posted on Tuesday, 27 July 2010 04:04

Gratitude for taking made the effort to debate silverlight, I feel strongly concerning it and love learning more on this area. If probable, as you gain expertise, would you mind updating your internet site with added information? This can be very useful 4 me.

Reid Browy

Posted on Tuesday, 27 July 2010 18:40

I should in reality be working

Add comment




  Country flag

biuquote
Loading