1 / 26

WPF Unleashed XAML Demystified.

WPF Unleashed XAML Demystified. By Prashanth Vijayaraghavan. XAML Defined. General purpose declarative programming language. XAML is the most concise way to represent user interfaces. Encourages separation of backend logic and front end appearance.

Download Presentation

WPF Unleashed XAML Demystified.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WPF Unleashed XAML Demystified. By Prashanth Vijayaraghavan

  2. XAML Defined • General purpose declarative programming language. • XAML is the most concise way to represent user interfaces. • Encourages separation of backend logic and front end appearance. • .Net 3.0 includes compiler, run time parser for XAML.

  3. Elements and Attributes • XAML maps .net namespaces, types, properties and events into XML namespaces, elements and attributes.

  4. Elements and Attributes (Cont) • Object Element. • Property Attribute. • Event Attribute.

  5. Elements and Attributes (Cont) • Standalone rendering VS Compilation mixing. • Order of property and event processing. A simple button which is rendered standalone

  6. Namespaces • XAML code must contain at least one namespace xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation” • Additional namespaces can be defined by giving distinct prefix. xmlns:x=“http://schemas.microsoft.com.winfx/2006/xaml”

  7. Property Elements Updating the WPF button with complex content

  8. Property elements (Cont..) • Object elements - properties set using xml attributes. • Property elements - properties set with xml element. - They can never have attributes eg:<Button.Content>ok</Button.Content>

  9. Type Converters • Type converters convert string representation to the desired data type. Eg:

  10. Type Converters (Cont..) • WPF provides type converters for many common data types like brush, color, fontweight, point etc. • Can create our own type converter by deriving from TypeConverter. • Type converter supports case insensitive strings.

  11. Markup Extensions • Like type converters, markup extensions evaluate a string value at run time and produce appropriate objects. • Attribute value enclosed in curly braces({}).

  12. Markup Extensions (Cont ..) • Escaping curly braces

  13. Children of object elements • All Xaml files must have single root object element which can contain hierarchy of child object elements. • Three types of children - A Value for content property. - Collection items. - A value that can be type converted to parent.

  14. The Content Property

  15. Collection Items Items property to insert individual items

  16. Dictionaries • System.Windows.ResourceDictionary is a commonly used collection type. • It supports adding of key value pair to any collection implementing Idictionary.

  17. Types in .NET FCL Integration with types from .net framework class library(int32)

  18. More Type Conversions Brush is an abstract base class for concrete classes such as SolidColorBrush, GradientBrush etc. Is equivalent to

  19. Loading and Parsing XAML at run time • xmlReader.load method parse XAML, create appropriate .net object and return an instance of root element.

  20. Naming XAML elements Name keyword for giving any element a name FindName method searches its children and returns the desired instance.

  21. Compiling XAML XAML compilation involves three things. • Converting a XAML file into a special binary format. • Embedding the converted content as a binary resource in the assembly being built. • Connecting XAML and procedural code.

  22. Compilation: Mixing XAML with procedural code Defining sub class in the root element Code behind file with the same class name given above

  23. Files generated when compiling xaml In the case of previous example • A Baml file (MyWindow.baml)- Embedded in the assemble as a binary resource. • A c# source file(MyWindow.g.cs)- Gets Compiled into the assembly.

  24. BAML- Binary application markup language • XAML that has been parsed, tokenized and converted into binary form. • XAML to BAML compilation does not include generation of procedural source code. • Faster to load and parse.

  25. Procedural code inside XAML • Contents of the code are put inside X:Code element

  26. Thank you

More Related