keyboard

Design Surface + XAML

The key elements of XAML syntax are:

  • Default namespace: An XML function that defines a set of elements (and their attributes) that can be used in a document. At runtime, these elements are mapped to classes in the .NET assembly;
  • Element: Using an XML element means that an object with the same name as the element will be created at runtime;
  • Attribute: At runtime, the value of the attribute will be set to the value of the property of the object created for the corresponding element. The XAML parser can also convert text to non-text types, including a numeric type, an enumerated type, multiple initial values of a type (for example, different sides of a box), or an entire object initialized with attribute values (for example, a SolidColorBrush of a specific color);
  • Nesting: placing one element inside another means that the created objects form a tree, whereby the nested object is assigned a default property (for example, one Child or Content property of the containing object) or it becomes one of several objects added to a default collection property (for example, a Children collection property);
  • Property element: If an object property is too complex to declare or parse from a textual XML attribute, the property element syntax is used to fully declare the object;
  • Attached properties: This allows the containing object to declare properties for each child object without requiring each child object’s class to have members (for example, a set of Button objects can be placed in a radial layout control that visually arranges buttons in a circle; this layout control requires each button to have an angle property value);
  • Extensibility: To represent elements that become types from other .NET assemblies (such as other controls or classes), use this type of XML namespace declaration;
  • x:Name: Similar to the ASP.NET ID attribute; to access created objects from within procedure code, give them a name;
  • Evaluated: The {} syntax is used to evaluate a value at runtime, such as accessing resources or binding to data.

You can (and may need to in some cases) use the procedural code in the MainPage.xaml.cs file to create a user interface and populate it with data. However, XAML provides a more efficient way to declare visual interfaces instead of writing procedural code, which can be significantly longer. Procedural code is still used for data models and data access.