Silverlight - How to incorporate usercontrol and master page

667 views Asked by At

I m novice to Silverlight... I have created a usercontrol and want to consume that in MainPage.xaml, pls let me know the syntex ( Xaml syntex if n e ) for that...

also Can I create a MasterPage sort of control and use all user controls in Silverlight ? If yes then pls let me know the code snippet for that as well or any link where all these are explained...

Thx in advance...

1

There are 1 answers

0
Jos van Egmond On BEST ANSWER

To use a UserControl from any other part of your XAML do this: In your MainPage.xaml, first you have to add the local namespace. In the

<UserControl xmlns ... >

part, add the following:

<UserControl xmlns ... xmlns:local="clr-namespace:YourLocalNameSpace">

This will be mostly auto-completed for you if you use VS2008/VS2010 or Blend. (The dots are there are an indicator that there is a lot of code there that is irrelevant)

Once you have a reference to the local namespace. You can add your other custom usercontrol like so:

<local:YourCustomUserControl />

Again, this will be autocompleted for you if you got the xmlns:local part right.

Something that is worth checking out is Expression Blend. It is mostly a drag/drop/point/click interface that will do these sort of semi-complicated XAML operations for you.

An idea in Silverlight that is similar to ASP.NET's MasterPage are control templates. I'm not going into detail here, because this article explains it quite well: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx

Alternatively, assume you were building a window that has a few pages. You want to create some chrome and a menu that is consistent no matter which page on the window you were looking at. You can create a UserControl that is the "frame" for your other UserControls. This frame contains the chrome and the menu, and it is a container for your other UserControls.

There are lots of methods to choose from here. Up to you. :)