Xaml - มหาวิทยาลัยขอนแก่น

Xaml - มหาวิทยาลัยขอนแก่น

XAML Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University What is XAML short for Extensible Application Markup Language, and pronounced zammel) Markup (declaraive) language used to

instantiate .NET objects XAML, like all XML-based languages, is casesensitive. That means you cant substitute

must be referenced in your project. Other Namespaces: Examples Heres how you would gain access to the basic types in the System namespace and map them to the prefix sys: Heres how you would gain access to the types youve declared in the MyProject namespace of the

current project and map them to the prefix local: Now, to create an instance of a class in one of these namespaces, you use the namespace prefix: Other Namespaces: Tips You can use any namespace prefix you want. The sys and local prefixes are commonly used when importing the System namespace and the

namespace for the current project Basically, XAML doesnt support parameterized constructors, and all the elements in WPF elem ents include a no-argument constructor If the class you want to use doesnt have a noargument constructor, you can supply the string representation of your data as content inside yo ur tag The Code-Behind Class using the Class attribute to make a functioning

application a way to connect the event handlers that contain your application code The x namespace prefix places the Class attribute in the XAML namespace the Class attribute tells the XAML parser to generate a new class which derives from the class t hatsnamed by the XML element. this example creates a new class named Window1, which derives from the base Window class.

Visual Studio helps you out by automatically creating a partial class where you can place y our event handling code. Naming Elements In order to read or change properties or attach and detach event handlers on the fly, the element must include a XAML Name attribute.

You can make this change by hand in the XAML document, or you can select the grid in the Visual Studio designer and set the Name property using the Properties window. Now you can interact with the grid in your Window1 class code by using the name grid1: Properties and Events in XAML The eight ball window includes four controls

Simple Properties and Type Converters the attributes of an element set the properties of the corresponding object. For example, the text boxes in the eight ball example configure the alignment, margin, and font: XAML parser needs to perform a conversion between

string values and non string properties by type converters type converters usually arent case-sensitive, which means both Foreground="White" and Foreground="white" have the same result. Complex Properties XAML provides another option: property- element syntax. The key detail that makes this work is the period (.) in the element name.

Markup Extensions sets a property value in a nonstandard way to an object that already exists to a property in another control by binding it dynamically can be used in nested tags or in XML attributes When theyre used in attributes, they are always bracketed by curly braces {}. the syntax: {MarkupExtensionClass

Argument}. Markup Extensions (cont.) For example In this case, the markup extension is the StaticExtension class. By convention, you can drop the final word Extension when referring to an extension class. The x: prefix indicates that the StaticExtension

is found in one of the XAML namespaces. markup extensions that are a part of the WPF namespaces, dont have the x: prefix Markup Extensions (cont.) Because markup extensions map to classes, they can also be used as nested properties Similar to

Attached Properties Properties that may apply to several controls but are defined in a different class In WPF, attached properties are frequently used to control layout. Two-part name syntax: DefiningType.PropertyName Nesting Elements

XAML documents are arranged as a heavily nested tree of elements Nested elements are evaluated in this order If the parent implements IList, the parser calls IList.Add() and passes in the child If the parent implements IDictionary, the parser calls IDictionary.Add() and passes in the child. W hen using a dictionary collection, you must also s et the x:Key attribute to give a key name to each i

tem. If the parent is decorated with the ContentProperty attribute, the parser uses the ch ild to set that property. Nesting Elements (cont.) each GradientStop should be added to the collection using the IList.Add() method:

Nesting Elements (cont.) Some properties might support more than one type of collection. In this case, you need to add a tag that specifies the collection class Special Characters By the rules of XML, XAML pays special attention to a few specific characters, such as & and < and >.

Special Characters (cont.) When the XAML parser reads this, it correctly understands that you want to add the text and it passes a string with this content, complete with angled brackets, to the Button.C ontent property. This limitation is a XAML detail and it wont affect you if you want to set the Button.Content property in code

Whitespace Use the xml:space="preserve attribute on your element to include a series of several spaces The xml:space attribute is a part of the XML standard Once you switch it on, all the whitespace inside that element is retained In this example, the text in the text box will include

the hard return and tab that appearbefore the actual text. It will also include the series of spaces i nside the text and the hard return that follows the t ext. Events Attributes can also be used to attach event handlers

Syntax: EventName="EventHandlerMethodName For example, the Button control provides a Click event. You can attach an event handler lik e this: This assumes that there is a method with the name cmdAnswer_Click in the code-behind class.

Events (cont.) The event handler must have the correct signature Events (cont.) The event model inWPF is different than in earlier versions of .NET

It supports a new model that relies on event routing Events (cont.) Visual studio with IntelliSense helps you add an event handler attribute. The Last Word Youve learn XAML syntax. Youve considered key XAML ingredients, such

as type converters, markup extensions, and atta ched properties. Youve learned how to wire up a code-behind class that can handle the events raised by your controls.

Recently Viewed Presentations

  • Ux PowerPoint Name - HPHS ENGINEERING

    Ux PowerPoint Name - HPHS ENGINEERING

    Center Line. Define the center of arcs, circles, or symmetrical parts. Half as thick as an object line. Section Line. Define where material is cut away. Short-Break Line. ... Extension Line. Shows where a dimension starts and stops. Used with...
  • Federal Trade Promotion and the National Export initiative

    Federal Trade Promotion and the National Export initiative

    Overview. visit export.gov for more. Federal Trade Promotion Coordination. Export Imperative: National & Firm-level Views. The National Export Initiative and NEI/NEXT.
  • WITHDRAWALS OBJECTIVE  Describe the need for a new

    WITHDRAWALS OBJECTIVE Describe the need for a new

    44 LD 513. A pre-FLPMA ROW for federal agencies. Notated on the Master Title Plat and historical index. Serves two purposes: Puts public on notice of federal improvements on public land (via notation) Protects those improvements when land is conveyed...
  • High Brightness Negative Ion Sources with High Emission ...

    High Brightness Negative Ion Sources with High Emission ...

    These results became the basis of secondary-emission sputtering negative ion sources with a microampere level intensity for tandem accelerators. A. Ayukhanov, PhD. Thesis, Secondary emission of negative ions with bombardment by alkali positive ions. 1961. U. A. Arifov, and A....
  • Round 1 Debrief - AM  What worked? Thorough

    Round 1 Debrief - AM What worked? Thorough

    Round 1 Debrief - AM. What worked?Thorough inspection processKitter and production scheduler always on time. What didn't work? Bubba wasn't available to move material. Faulty stamp. Better way to handle oven insertion/bigger oven?
  • The Manycore Shift: Making Parallel Computing Mainstream Bart

    The Manycore Shift: Making Parallel Computing Mainstream Bart

    Gordon Moore - Intel - 1965. Let's sell processors. Moore's law has been a good excuse to stick our heads in the sand when new versions of software ran slower than their predecessors: "in a few years time, hardware will...
  • 1: Expression networks

    1: Expression networks

    Trick: in a tree each node has only one parent! Chow-liu algorithm Chow-Liu tree learning algorithm Objection function: Chow-Liu: For each pair of variable xi and xj Compute empirical distribution: Compute mutual information: Define a graph with node x1,…, xn...
  • City of Houston Property Insurance Renewal

    City of Houston Property Insurance Renewal

    Annual Property Insurance Renewal Process. Broker of Record: McGriff, Seibels & Williams of Texas, Inc. Contract with City of Houston since September 1, 2014. Markets the City's Insurance to National and International Markets via RFP prepared by the COH: Request...