Using the Silverlight HeaderedContentControl
page 2 of 5
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26945/ 43

Understanding Content Controls

If you've seen a control with the Content property in Silverlight (which there are many), then you see one of the most common types of controls in the framework.  Content controls can take a variety of values in its content property.  In its simplest form, the content of the control could be text or some other primitive value (integer, etc.).  But content controls are not just limited to primitive data.  Content controls can accept any type of other Silverlight element within itself.  This is done by using long-hand syntax in the fom of:

Listing 1: Long-Form Syntax

<HeaderedContentControl.Content>
      <TextBlock Text="My Content" />
</HeaderedContentControl.Content>

In this way, the content property can store another Silverlight element, but it can only store a single element.  This may seem like a bad idea or even a bug, so how do you get around storing more than one element?  You could use a custom control or a user control, but at its simplest form, it could be using a panel control, as in:

Listing 2: Using a panel for content

<HeaderedContentControl.Content>
      <StackPanel>
             <TextBlock Text="My" />
            <TextBlock Text="Content" />
       </StackPanel>
</HeaderedContentControl.Content>

While content controls have only one child, panel-based controls or items-based controls, can store multiple children.  So this type of element meets this one control requirement, and the panel itself can store multiple elements.  It's a two-step process of sorts.  This feature isn't unique to the HeaderedContentControl object, but is a construct in Silverlight (and is also available in WPF).


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 7:07:19 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search