IT tutorials
 
Mobile
 

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

11/25/2014 3:16:44 AM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

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
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS