Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.

Slides:



Advertisements
Similar presentations
Module 1: Creating an Application by Using Windows Presentation Foundation Overview of WPF Creating a Simple WPF Application Handling Events and Commands.
Advertisements

Master Pages, User Controls, Site Maps, Localization Svetlin Nakov Telerik Corporation
An Introduction to XML Based on the W3C XML Recommendations.
Data Binding in GUI Application Development Patrick O’Brien.
The Web Warrior Guide to Web Design Technologies
Dinko Jakovljević Microsoft Student Partner | BambooLab
JavaServer Faces. Objectives To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical elements of JavaServer Faces.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Advanced Object-Oriented Programming Features
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
4/20/2017.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Internet Skills An Introduction to HTML Alan Noble Room 504 Tel: (44562 internal)
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
1 COS240 O-O Languages AUBG, COS dept Lecture 33 Building Apps Technologies C# (WPF part 1)
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
Windows Presentation Foundation. Goal The goal of Windows Presentation Foundation (WPF) is to provide these advances for Windows. Included in version.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CS134 Web Design & Development Creating a Basic Web Page Mehmud Abliz.
Learning Web Design: Chapter 4. HTML  Hypertext Markup Language (HTML)  Uses tags to tell the browser the start and end of a certain kind of formatting.
Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and attributes Create.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
New Perspectives on XML, 2nd Edition
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
WPF – Windows Presentation Foundation what is it, what can you do with it and how do you get started.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
XP Tutorial 8 Adding Interactivity with ActionScript.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
2.1 XHTML. Motto High thoughts must have high language. –Aristophanes.
1 Catching up on Rich Clients (round 1) Mike Ormond, Mike Taulty Developer & Platform Group Microsoft Ltd
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
Working with XML. Markup Languages Text-based languages based on SGML Text-based languages based on SGML SGML = Standard Generalized Markup Language SGML.
The idea of adding markup instructions to documents is not new. Before computers, authors would make annotations by hand in their written or typed documents.
Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
WPF (Avalon), Windows App GUI Windows App GUI Web App GUI Web App GUI HTML HTML XML XML WPF WPF LINQ LINQ.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Product Training Program
Introduction to Silverlight
ASP.NET Forms.
Introduction to Silverlight
XAML User Interface Creation in C#
WPF AKEEL AHMED.
.NET and .NET Core 7. XAML Pan Wuming 2017.
Web Development Using ASP .NET
New Perspectives on XML
Presentation transcript:

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 case-sensitive. That means you can’t substitute for can be applied to many different problem domains Visual Studio or Microsoft Expression Blend can be used to generate the XAML

Advantages of XAML XAML code is short and clear to read Separation of designer code and logic Graphical design tools like Expression Blend require XAML as source. The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer

XAML vs. Code XAML version much shorter and clearer to read

The Variants of XAML WPF XAML encompasses the elements that describe WPF content, such as vectorgraphics, controls, and documents. XPS XAML (XML Paper Specification) is the part of WPF XAML that defines an XML representation for formatted electronic documents. Silverlight XAML is a subset of WPF XAML that’s intended for browser applications. WF XAML encompasses the elements that describe Windows Workflow Foundation (WF) content.

XAML Compilation When you compile a WPF application in Visual Studio, all your XAML files are converted into BAML and that BAML is then embedded as a resource into the final DLL or EXE assembly

XAML Basics Every element in a XAML document maps to an instance of a.NET class. The name ofthe element matches the name of the class exactly. For example, the element instructs WPF to create a Button object. As with any XML document, you can nest one element inside another. However, nesting is usually a way to express containment You can set the properties of each class through attributes. However, in some situations an attribute isn’t powerful enough to handle the job. In these cases, you’ll use nested tags with a special syntax.

XAML Basics (cont.) The top-level Window element, which represents the entire window The Grid, in which you can place all your controls For the Window element you’ll find several interesting attributes, including a class name and two XML namespaces Also find the three properties which tells WPF to create a window with the caption Window1 and to make it 300 by 300 units large

XAML Namespaces To figure out which class you really want, the XAML parser examines the XML namespace that’s applied to the element. The xmlns attribute is a specialized attribute in the world of XML that’s reserved for declaring namespaces

XAML Namespaces (cont.) In the sample document shown earlier, two namespaces are defined: is the core WPF namespace this namespace is declared without a namespace prefix, so every elementis automatically placed in this namespace is the XAML namespace. This namespace is mapped to the prefix x. That means you can apply it byplacing the namespace prefix before the element name (as in ).

Using Other Namespaces You need to map the.NET namespace to an XML namespace. XAML has a special syntax for doing this Prefix is the XML prefix you want to use to indicate that namespace in your XAML markup. For example, the XAML language uses the x: prefix. Namespace is the fully qualified.NET namespace name. AssemblyName is the assembly where the type is declared, without the.dll extension. This assembly must be referenced in your project.

Other Namespaces: Examples Here’s how you would gain access to the basic types in the System namespace and map them to the prefix sys: Here’s how you would gain access to the types you’ve 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 doesn’t support parameterized constructors, and all the elements in WPF elements include a no-argument constructor If the class you want to use doesn’t have a no-argument constructor, you can supply the string representation of your data as content inside your 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 that’snamed 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 your 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 aren’t 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 they’re 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, don’t 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. When using a dictionary collection, you must also set the x:Key attribute to give a key name to each item. If the parent is decorated with the ContentProperty attribute, the parser uses the child 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.

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.Content property. This limitation is a XAML detail and it won’t 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 inside the text and the hard return that follows the text.

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 like 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 You’ve learn XAML syntax. You’ve considered key XAML ingredients, such as type converters, markup extensions, and attached properties. You’ve learned how to wire up a code-behind class that can handle the events raised by your controls.