IT tutorials
 
Mobile
 

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).

Image

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:

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

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:

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

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.

 
Others
 
- 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
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us