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.

Alfred Harbour

Posted on Sunday, 8 August 2010 09:56

Marvelous! Not clear for me, how often you�d updating your site?

Rodolfo Browers

Posted on Sunday, 8 August 2010 13:27

computer repair saint paul

Posted on Tuesday, 10 August 2010 05:25

Great information!  I just love your blog.  I can't wait to hear more from you.

Reid Browy

Posted on Tuesday, 10 August 2010 08:14

thanx silverlight

Annie Bondurant

Posted on Monday, 16 August 2010 17:43

lol, thx!

miami flat fee mls listing

Posted on Wednesday, 18 August 2010 16:28

Hey,

I wanted to say that I have been reading for a few months on and off and I would like to sign up for the daily feed. I am not to computer smart so I'll give it a try but I might need some help. This is a good find and I would hate to lose contact, and maybe never discover it again.

Anyway, thanks again and I look forward to posting again in the future!

realtouch

Posted on Monday, 30 August 2010 03:41

I take great delight in your blog, Its very good to observe not every person is just posting a mess of waste now a days!

realtouch

Posted on Monday, 30 August 2010 05:59

I care for your blog, Its good to find not all people is just posting a bunch of rubbish these days!

clarinet overhaul

Posted on Tuesday, 31 August 2010 12:47

Great tutorial. You make it so easy.

Add comment




  Country flag

biuquote
Loading