WPF decryption reading notes
|
Get your FREE Diabetes Recipes eBook! |
A, XAML definition
XAML is a relatively simple, common declarative programming language, which is suitable with the build and initialization. NET objects.
XAML is just a use. NETAPI method.
Second, the elements and characteristics
XAML specification defines a number of rules used to. NET namespaces, types, properties and events mapped to XML namespaces, elements and features.
XAML C # System.Windows.Controls.Button b = new System.Windows.Controls.Button (); b.Content = “OK”;
Although the two codes are the same, but you can quickly view in IE browser XAML, will also see a live button on the browser window. The C # code, you must use an additional code editor compiled before use.
In the definition of an XML element in XAML (called object elements) and. NET in the instance of a corresponding object (always use the default constructor) are equivalent.
Set a feature of the object element (attribute), and set a named property (property attribute, called attribute property) or the same name as an event handler to set a time handler (also known as event characteristics), is equivalent.
Code
XAML C # System.Windows.Controls.Button b = new System. Windows.Controls.Button (); b.Click = new System.Windows.RoutedEventHandler (button_Click); b.Content = “OK”;
Note: XAML and C # as are case-sensitive. However, the type of XAML converters are not case sensitive.
Third, the namespace
XAML file in the root object element must specify at least one XML namespace used to validate themselves and their child elements. You can (in the root element or child elements) of additional XML namespace declaration, each identifier of a namespace must have a unique prefix
For example: WPF’s XAML files will use the second namespace prefix X (denoted xmlns: x not just xmlns)
xmlns: x = “http://schemas.microsoft.com/winfx/2006/xaml”, which is the XAML language namespace mapping System.Windows.Markup namespace for the type, but it also defines the XAML compiler parser, or some special instructions.
WPF to all of the following. NET namespace mapped to the XML namespace
http://schemas.mircosoft.com/winfx/2006/xaml/presentation, and this name space will be used throughout the book.
(1) System.Windows
(2) System.Windows.Automation
(3) System.Windows.Controls
(4) System.Windows.Controls.Primitives
(5) System.Windows.Data
(6) System.Windows.Documents
(7) System.Windows.Forms.Intergration
(8) System.Windows.Ink
(9) System.Windows.Input
(10) System.Windows.Media
(11) System.windows.Media.Animation
(12) System.Windows.Media.Effects
(13) System.Windows.Media.Imaging
(14) System.Windows.Media.Media3D
(15) System.Windows.Media.Media3D
(16) System.Windows.Media.TextFormatting
(17) System.Windows.Navigation
(18) System.Windows.Shapes
Because it is more than one pair of a mapping, WPF designers need to ensure not to introduce two classes of the same name, although they are in different classes. NET namespace.
Fourth, property element: that is to replace the property with the property characteristics. Property value is set to XML instead of XML features.
Property element of the period to distinguish the object element (Objectelement) and the property element (property element), they are always to “type name. Attribute name” of the form, and also always be included in the object element type name, but these attribute element does not have its own characteristics.
Property element can also be used for simple property values.
Fifth, the type converter
The two code snippets above effect is the same, but there is one thing: White Background how equal with it? This relates to the type of converter.
The example above provides a number of how to use XAML attribute value string to set some details of the type is neither of these attributes String, not Object type, in this case: XAML compiler or interpreter is needed to find a type converter The conversion from a string expression to know how to convert the data type you want.
WPF provides a number of common data type conversion (for example: Brush, Color, FontWeight, Point), they are inherited and the TypeConverter class. (Example: BrushConverter, ColorConverter), you can also write custom column data type converter, and the XAML language is different, the type converter to support case-insensitive string.
Six, marking extension
Markup extension is like the same type of converter can be used to extend the expressive power of XAML. They are calculated at run time, the string value of a property, (except for some built-in, in order to improve the performance of the marker at compile time extension), and generate an appropriate string based on the object.
But with a different type of converter is the XAML markup extension through the display of, and consistent syntax calls, so the markup extension is the best way to expand XAMl.
As long as the value of the properties of a pair of “curly braces” enclosed, XAML compiler or interpreter will be recognized as it is a “Extensible Markup value”, rather than an ordinary string, or some other things need to type conversion .
Code
Curly brackets in each of the first identifier is a sign extension class names. By convention: the name of this class are to Extension suffix. But when you use it in XAML, you can not use the suffix. This case NullExtension we see x: Null, StaticExtension we see x: static.
NullExtension and StatictExtension are System.Windows.Markup namespace classes, you must use x to locate them. Binding is System.Windows.Data namespace, so it the default namespace in the XML can be found under.
If the extended support, you can use commas to separate parameters to specify their value.
Location parameter (in this case, the SystemParameters.IconHeight) is expanded as a string argument to the constructor of the class. Named parameters such as (in this case the Path and RelativeSource) can be used to construct a good extension object to set the corresponding attribute name. These attribute values can be marked expansion of the value of their own (using absconded braces, such as RelativeSource), it can be plain text values can also be cast by an ordinary process.
As well as in the example above, a special case: NullExtension allow you to set Background to NULL, but BrushConvertor and other types of converters do not support this.
StaticExtension allows the use of static properties, fields, constants and enumerations, rather than using hard-coded values written in XAML.
Because Extensible Markup is the default constructor of the class, they can be used in conjunction with the property element.
Code
The conversion was able to perform because: these extensions are marked with the parameter of the constructor argument using the property attribute syntax ã€Location】 corresponding argument property. For example: StaticExtension a Member property, and before the parameter passed to the constructor of the argument is a meaning. RelativeSource have a corresponding constructor argument corresponds to the Mode property.
Sorry, the comment form is closed at this time.


Comments
No comments yet.