WindowsPhone custom controls (1)-control class library Analysis

Source: Internet
Author: User
++ ++

This article is original on this site. You are welcome to repost it! Reprinted please indicate the source:

Http://blog.csdn.net/mr_raptor/article/details/7251942

++ ++

To make your applications more personalized, we usually customize our own controls during WP7 development, set various templates in the Custom Controls, bind data, and modify control behaviors, but for many friends, why? I am not very clear. I can't find a clue when I look at MSDN. This article is to analyze the inheritance relationship of the control class library in the custom control. Why? If you think this article has a unique point of view, it will be of great help to you. Thank you.

 

I. Control Classification

Let's start with the familiar control classification, because this understanding is more intuitive.

The basic controls in WP7 can be divided into the following four types:

1. Text control: Mainly used to display and input text

2. Content Control: it is mainly used to include a child control element UIElement (UIElement is the base class of all visual UI controls. I call it the third-generation control ancestor)

3. Item Set control: it can be known from the name. It is a control that contains multiple sub-items, such as ListBox.

4. Container Control: it can contain multiple child control elements (UIElement)

 

Common basic controls are shown in the following table.

Widget

Control Type

Content Attributes

TextBlock

Text Control

TextBlock. Text

TextBlock. Inlines

TextBox

Text Control

TextBox. Text

PasswordBox

Text Control

PasswordBox. Password

Button

Content Control

ContentControl. Content

CheckBox

Content Control

ContentControl. Content

RadioButton

Content Control

ContentControl. Content

ListBoxItem

Content Control

ContentControl. Content

ListBox

Item collection Control

ItemsControl. Items

ItemsControl. ItemsSource

Canvas

Container Control

Panel. Children

Grid

Container Control

Panel. Children

StackPanel

Container Control

Panel. Children

Address: http://blog.csdn.net/mr_raptor/article/details/7251942

Ii. Main controls

The System. Windows. Controls namespace mainly contains the following control base classes:

  • Control
  • ContentControl
  • ItemsControl
  • Panel

1. Control: indicates the base class of the user interface Control.

 

 

Main attributes:

  • Control. Template attributes:

Apply ControlTemplate to the Control. Template attribute to define its appearance. All subclasses that inherit the Control class inherit the Template attribute, which means that you can customize the Control sub-Control through custom ControlTemplate.

Note: It has a sub-class UserControl used to quickly create controls. However, you cannot customize ControlTemplate and apply it to UserControl.

 

Main events:

  • GotFocus, LostFocus

Callback when the control gets or loses focus

  • MouseLeftButtonUp, MouseMove, MouseLeftButtonDown

Callback when the control is clicked and moved separately

  • ManipulationStarted, ManipulationDelta, ManipulationCompleted

ManipulationStarted is called back when you start operations on the control. ManipulationDelta is called back when you operate the control and change the position. ManipulationCompleted is called back when the control is stopped.

  • SizeChanged

Callback when the ActualHeight or ActualWidth attribute representing the control size changes

 

2. ContentControl: it is the base class of other content controls, indicating the content controls that contain individual elements. Controls such as Button, CheckBox, and ScrollViewer directly or indirectly inherit from this class.

 

Main attributes:

  • ContentControl. Content attributes:

The ContentControl. Content attribute can be any type of object, such as string, UIElement, or DateTime. When ContentControl. Content is set to UIElement, UIElement is displayed in ContentControl. When ContentControl. Content is set to another type of object, the string representation of this object is displayed in ContentControl.

Note:ContentControl has a limited default style. To enhance the appearance of the control, you can create a new
DataTemplate type attributes are used for customization.

  • ContentControl. ContentTemplate attributes:

It is a DataTemplate object element that defines the content display appearance of the ContentControl.

Address: http://blog.csdn.net/mr_raptor/article/details/7251942

3. ItemsControl: it is the base class of the item collection class.

 

Main attributes:

  • Items attributes:

To display a fixed list, use one or more FrameworkElement sub-objects to fill in the ItemsControl. Items attribute, and do not specify ItemsSource.

  • ItemsSource attributes:

If you want to display data in the object data source, you should specify ItemsSource as a reference to an object. Generally, this can be achieved through the Binding declaration,

  • ItemsPanel attributes:

Sets the layout of the control that is used to customize the item set. It is an ItemsPanelTemplate type element.

  • ItemTemplate attributes:

Set this attribute to specify the data display appearance of each Item in the Item set control. It is a DataTemplate type element.

 

4. Panel: is the base class of the container control, such as Canvas, Grid, and StackPanel.

 

 

You can customize the layout behavior by inheriting from the Panel and using the MeasureOverride and ArrangeOverride methods to override the default measurement and arrangement behavior.

Address: http://blog.csdn.net/mr_raptor/article/details/7251942

The main attributes and methods in the base class described above are the things we modify when customizing controls. We can see from the inheritance relationship diagram in the middle that the Panel class has no inheritance relationship with the Control class, this is determined from the ancestor's generation. The features of their children are different, so the customization of the two major branch classes is different. The Panel class is mainly a container control that contains other controls, the main custom definition of the container control is to set the layout between different included controls, so the two measurement methods are reloaded. The Contorl class is a user interaction class with an appearance and interactive operations. Its subclass is mainly to customize its appearance and operations, that is to say, you can set its Template attribute and reload specific events to achieve the goal.

The ContentControl class is a subclass of the Control class and has the Control feature. However, it is a content Control mainly used to include a UIElement. since it contains a UIElement, you need to set the Content attribute of the UIElement to determine what UIElement is included. You can use ContentTempalte to define the appearance of the UIElement. Therefore, to customize the appearance, create a new DataTempalte, apply to the ContentTempalte attribute.

The ItemsControl class is a subclass of the Control class and inherits the inherited items. It is an Item collection class and can contain multiple sub-Item items. Therefore, it has the Items attribute and ItemsSource to allow users to specify which sub-Items. Similarly, the ItemtPanel attribute is used to specify the layout of each sub-item, each subitem is a content control that features ContentControl. Therefore, you must specify the appearance of each item through the ItemTempalte attribute.

 

++ ++

This article is original on this site. You are welcome to repost it! Reprinted please indicate the source:

Http://blog.csdn.net/mr_raptor/article/details/7251942

++ ++

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.