Daan Luttik
Daan Luttik

Reputation: 2855

Custom GUI object

I know how to create a simple XAML interface for a page, but I spend a lot of my time copying and pasting code since I have no idea how to create reusable XAML in a proper way, I know about styles but they don't quite fill the role. What I would prefer to do is to call them in the following way:

<CustomElement attribute1="bla" attribute2="{Binding somethingElse}"/>

Just like all the other GUI objects in the Silverlight framework. Any help or hint would be useful.

Upvotes: 1

Views: 165

Answers (1)

Bas
Bas

Reputation: 27085

Basically there are two options. Both solutions act like any other Silverlight control. They can be inserted at random places in pages like you would normally insert a Button or a StackPanel. The option of choice depends on the specific reuse scenario.

  1. Create a UserControl. These define their own XAML layout and are very easy to create. Consider looking at ScottGu's tutorial.
  2. Create a custom control. Custom controls also define their own XAML layout but through templating and styling. They are harder to create but support templating; this means other developers can decide that they will use the code behind your control, but specify a completely different layout. For more information look at Silverlight templating.

For a (much) better understanding, please look at this page comparing the features of UserControls and custom controls more in-depth.

Upvotes: 2

Related Questions