IT tutorials

Windows Phone 8 : Content Controls - Defining the Default Content Property

11/25/2014 3:16:44 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Controls that are derived from ContentControl are able to host a single object. ContentControls include Buttons, ListBoxItems, and containers such as the PhoneApplicationFrame and the ScrollViewer control (see Figure 1).


FIGURE 5.3 Content controls (excludes some mapping related types).

ContentControl has a Content property, whose value can be of any type. The way content is presented in the UI, however, depends on its type and whether a DataTemplate is associated with the ContentControl. The following lists the three ways in which content is presented:

- UIElementsIf the object derives from UIElement, the object will be rendered.

- Non-UIElements—If the object does not derive from UIElement, its ToString method is used to retrieve a textual representation of the object. If the ToString method has not been overridden, the result is the fully qualified class name of the object.

- Non-UIElements with an associated DataTemplate—The ContentControl.ContentTemplate allows you to specify a DataTemplate, either as a StaticResource or inline, which is used to display an object. Data binding expressions within the DataTemplate are used to extract the object’s property values and to render them.

To better understand the Content property, let’s look at a commonly used ContentControl: the Button control. With a Button, you can set its Content property to a string, as shown:

<Button Content="Tap me!" />

Unlike the TextBlock control, for example, the Button control does not have a Text property, yet by setting the Content property to a string, the Button displays the string.

Defining the Default Content Property

The Content property is the default property of the ContentControl. The ContentPropertyAttribute specifies which property of a class can be interpreted as the main content property when the class is parsed by a XAML processor. This means that when, for example, a TextBlock is placed as a nested element of a Button, the TextBlock is rendered within the button itself:

    <TextBlock Text="Press me!" Foreground="Orange" />

To further illustrate, the built-in control template for the Button control includes a Border that contains a TemplateBinding to the Content property of the Button, as shown in the following excerpt:

    <ContentControl x:Name="ContentContainer"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    Content="{TemplateBinding Content}" />

When the Button is rendered using its built-in style, the Content value, whatever it may be, is placed within a Border.

If you examine the source code for the ContentControl using Reflector, you see that a ContentPropertyAttribute is used to indicate to the runtime that the Content property is the default property:

[ContentProperty("Content", true)]
public class ContentControl : Control
{ ... }

When creating your own custom controls, you can decorate a class with a ContentPropertyAttribute to specify a different default property.

- Windows Phone 8 : Control Type Taxonomy - Identifying Controls Not Supported or Absent in Windows Phone
- Windows Phone 8 : Working with People - Facebook Integration (part 5) - Viewing a Friend’s Facebook Albums
- Windows Phone 8 : Working with People - Facebook Integration (part 4) - Writing on a Friend’s Facebook Wall , Viewing Facebook Wall Photos
- Windows Phone 8 : Working with People - Facebook Integration (part 3) - Commenting on a Wall Post
- Windows Phone 8 : Working with People - Facebook Integration (part 2) - Viewing a Wall Post, Viewing Comments to Wall Posts
- Windows Phone 8 : Working with People - Facebook Integration (part 1) - Connecting to Facebook
- Windows Phone 8 : Working with People - Rooms (part 8) - Adding an Appointment to the Shared Calendar , Creating a New Shared Note, Viewing Shared Notes
- Windows Phone 8 : Working with People - Rooms (part 7) - Viewing Shared Photos and Videos, Viewing the Shared Calendar
- Windows Phone 8 : Working with People - Rooms (part 6) - Sharing Photos and Videos
- Windows Phone 8 : Working with People - Rooms (part 5) - Deleting a Room, Using Group Chat
Top 10
Technology FAQ
- Microsoft ebs security server configuration
- IIs7 on Windows server 2003
- How to Configure Failover Clusters With Win 2008 Server R2?
- Windows 2008 Network Load Balancing
- Windows Server 2008 - Group Policy Management - Remove Computer Management
- Remove shortcuts possibility in a web page or to put in favorite
- HTA Dynamic Drop Down List
- IIS host header and DNS
- VMware or MS Virtual Server?
- Adobe Acrobat 9 inserting tab pages
programming4us programming4us