as an ASP.Net developer, I am familiar with Master Pages as template for web pages. Is there any mechanism in silverlight which is equivalent with Master Pages in ASP.Net?
Because I don’t want to repeat myself creating similar control like:
ControlA
<UserControl>
<Grid>
<Button Click="ClickMe" />
<Button Click="CancelMe" />
<TextBlock />
<StackPanel>
<!-- content start here -->
<Rectangle />
<!-- content end here -->
</StackPanel>
<Grid>
</UserControl>
ControlB
<UserControl>
<Grid>
<Button Click="ClickMe" />
<Button Click="CancelMe" />
<TextBlock />
<StackPanel>
<!-- content start here -->
<Canvas />
<!-- content end here -->
</StackPanel>
<Grid>
</UserControl>
You can use
ItemsControlfor this specific kind of templating. AnItemsControlis a type ofControlthat can contain multiple items, such as strings, objects, or other elements. Transform your XAML as illustrated below. Remember to derive your class fromItemsControlinstead ofUserControlin your code-behind.Assume that your new class is named
MasterPageControl. You can use the control like this: