XAML Basics

  • View
    39

  • Download
    5

Embed Size (px)

DESCRIPTION

XAML Basics. Elements, Properties and Stuff. Doncho Minkov. Telerik Software Academy. http://academy.telerik.com. Technical Trainer. http://minkov.it. Table of Contents. XAML Syntax XML Elements Properties XAML Controls Control resources Variables in XAML Collections. XAML Syntax. - PowerPoint PPT Presentation

Text of XAML Basics

XAML Basics

XAML BasicsElements, Properties and StuffDoncho MinkovTelerik Software Academyhttp://academy.telerik.com Technical Trainerhttp://minkov.it , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Table of ContentsXAML SyntaxXMLElementsPropertiesXAML ControlsControl resourcesVariables in XAMLCollections , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , XAML Syntax , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , XAML SyntaxXAML stands for eXtensible Application Markup Languagei.e. uses syntax that is actually pure XMLVery similar to HTMLMeant to build applications' UIBriefly XAML consists ofElementsPropertiesElements may have properties , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , XAML ApplicationA XAML application consists of many elementsThe first (the root) is either Window or UserControlDepends if you are using WPF or Silverlight

Ok

The Content of the Application

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , XAML SyntaxLive Demo , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Elements and AttributesUI elements have a set of common properties and functionsSuch as Width, Height, Cursor, and Tag propertiesDeclaring an XML element in XAMLEquivalent to instantiating the object via a parameterless constructorSetting an attribute on the object elementEquivalent to setting a property with the same name7 , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Elements and Attributes (2)Elements and attributes are case sensitiveThe attributes can be enclosed in single quotes (') or double quotes (")8 , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , 8Elements and AttributesLive Demo , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Property Elements

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , *(c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*10##Property ElementsNot all properties have just a string valueSome must be set to an instance of an objectXAML provide syntax for setting complex property values, called property elementsTake the form TypeName.PropertyName contained inside an TypeName element11

A property element , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Property ElementsLive Demo

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , *(c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*12##Content Properties

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , *(c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*13##Content PropertiesOne of the element's properties is defaultKnown as content propertyTypically contains the child elementsContent properties are used without prefix:14

A content propertyA property element , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , ,

Attached Properties

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , *(c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*15##Attached PropertiesAttached properties are special kind of propertiesCan be attached to any objectNot just the one defining the propertyThe syntax is the same as setting a normal propertyThe property must be prefixed with the name of the element defining the property and a dot16 , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Attached Properties (2)Attached properties allow common behavior to be applied to arbitrary elementsAllow a child item to access a property of its parent itemThe base of Attached BehaviorCommonly used attached properties:Canvas.Left and Canvas.RightGrid.Row, Grid.Column and Grid.Rowspan17 , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Attached Properties ExampleUsing the Canvas.Left and Canvas.Top attached properties to position EllipsesThe default value is 018

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Attached PropertiesLive Demo

, , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , *(c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*19##Dependency Properties , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , Dependency PropertiesA Dependency Properties are properties that extend the functionality of a common language runtime (CLR) propertyInteract with properties directly and never know that they are implemented as a dependency propertyThe purpose of dependency properties is to provide a way to compute the value of a property based on the val