XAML. Chapter 2 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon Understanding XAML

Similar documents
LAYOUT. Chapter 3 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon

ROUTED EVENTS. Chapter 5 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon

STYLES AND BEHAVIORS

SHAPES & TRANSFORMS. Chapter 12 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ.

Windows Presentation Foundation Programming Using C#

Introduction. Thank you for picking up Silverlight 1.0 Unleashed! IN THIS CHAPTER. . Who Should Read This Book?. Software Requirements

Microsoft Visual Studio 2010

Beginning Silverlight 5 in C #

DOT.NET MODULE 6: SILVERLIGHT

10267A CS: Developing Web Applications Using Microsoft Visual Studio 2010

Developing Windows Applications with Microsoft Visual Studio 2010

WPF and MVVM Study Guides

NET 3.0 and NET 3.0 contains four building blocks, shown in the figure below:

Introduction. Part I: Silverlight Fundamentals for ASP.NET Developers 1

PROGRAMMING WITH THE MICROSOFT.NET FRAMEWORK USING MICROSOFT VISUAL STUDIO 2005 Course No. MS4995A 5 Day PREREQUISITES COURSE OUTLINE

2310C VB - Developing Web Applications Using Microsoft Visual Studio 2008 Course Number: 2310C Course Length: 5 Days

SLD 2.0 Implementation Guide

Windows Presentation Foundation (WPF)

DEVELOPING WINDOWS APPLICATIONS WITH MICROSOFT VISUAL STUDIO 2010

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

Microsoft Visual Basic 2005: Developing Applications Additional Topics

10262A VB: Developing Windows Applications with Microsoft Visual Studio 2010

Introduction p. 1 Who Should Read This Book? p. 2 Software Requirements p. 3 Code Examples p. 3 How This Book Is Organized p. 4 Conventions Used in

Hypertext Markup Language, or HTML, is a markup

Introduction to Data Templates and Value Converters in Silverlight

Team Developer 6.1. Configure the color-coding in the Tools Preferences dialog under the Outline tab.

DE Developing Windows Applications with Microsoft Visual Studio 2010

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

Introduction to Programming Microsoft.NET Framework Applications with Microsoft Visual Studio 2005 (C#)

UNIT V *********************************************************************************************

The Extensible Markup Language (XML) and Java technology are natural partners in helping developers exchange data and programs across the Internet.

Chapter 1 Getting Started with Windows Presentation Foundation

Windows Presentation Foundation

Beginning ASP.NET. 4.5 in C# Matthew MacDonald

CS3240 Human-Computer Interaction Lab Sheet Lab Session 3 Designer & Developer Collaboration

Windows Presentation Foundation. Jim Fawcett CSE687 Object Oriented Design Spring 2018

Programming Windows, Sixth Edition

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

Apex TG India Pvt. Ltd.

C# Language. CSE 409 Advanced Internet Technology

--Microsoft-- --Windows Phone--

Programming in C# for Experienced Programmers

Windows Presentation Foundation for.net Developers

CSE 12 Abstract Syntax Trees

Getting Started with ExcelMVC

WPF. Source Module 01: Lesson1

ComponentOne. HyperPanel for WPF

Developing Windows Applications with Microsoft Visual Studio 2010 (MS 10262)

Course 80436A C/Side Introduction in Microsoft Dynamics NAV 2013

CS 31: Intro to Systems Caching. Kevin Webb Swarthmore College March 24, 2015

Microsoft Silverlight 4 Business Application Development

Developing Windows Applications with Microsoft Visual Studio 2010

Syntax Analysis. Chapter 4

Building Web Sites Using the EPiServer Content Framework

Road Map for Essential Studio 2010 Volume 1

Visualization Insider A Little Background Information

ALPHAPRIMETECH 112 New South Road, Hicksville, NY 11801

Quick Start - WPF. Chapter 4. Table of Contents

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

WEB ADMINISTRATION (WEBMASTER)

CS 31: Intro to Systems Caching. Martin Gagne Swarthmore College March 23, 2017

A Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER?

Pro XAML with C# From Design to Deployment on WPF, Windows Store, and Windows Phone. Buddy James. Lori Lalonde

HLSLand Pixel Shaders for XAML. Developers. Walt Ritscher O'REILLY* Farnham Koln Sebastopol. Beijing. Tokyo. Cambridge

WEB GRAPHICS ADOBE PHOTOSHOP CS3. Learning Outcomes:

BCIS 4650 Visual Programming for Business Applications

CHAPTER 1: INTRODUCING C# 3

The IVI Driver Standards

Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill

20483BC: Programming in C#

Personal Information Manager Overview & Installation Guide

Index. Application programming interface (API), 38. Binary Application Markup Language (BAML), 4

PDSA.NET Productivity Framework Deployment Manual

DOT NET SYLLABUS FOR 6 MONTHS

Introduction. I hope you find this book to exhibit all of these attributes.

6.001 Notes: Section 15.1

Department of Computer Applications

CHANNEL9 S WINDOWS PHONE 8.1 DEVELOPMENT FOR ABSOLUTE BEGINNERS

And FlexCel is much more than just an API to read or write xls files. On a high level view, FlexCel contains:

The diverse software in Adobe Creative Suite 2 enables you to create

Dot Net Framework 4.0: Advanced Microsoft C#.NET Web Development

InstallAware for Windows Installer, Native Code, DRM, Virtualization

Practical WPF. Learn by Working Professionals

1. Introduction to the Common Language Infrastructure

WebAccess Configuration Manual MTConnect Driver Guide

Applied WPF 4 in Context US $49.99 SOURCE CODE ONLINE

Hands-On Lab. Hello Windows Phone

Course 2D_WPF: 2D-Computer Graphics with C# + WPF Chapter C1a: The Intro Project Written in XAML and C#

Picture This: Creating Controls on the Fly

INTERNAL ASSESSMENT TEST 1 ANSWER KEY

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

Fundamentals of XAML and Microsoft Expression Blend

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

CHAPTER 1: INTRODUCTION TO THE IDE 3

A Guide to CMS Functions

Advanced Layouts in a Content-Driven Template-Based Layout System

CS708 Lecture Notes. Visual Basic.NET Object-Oriented Programming. Implementing Client/Server Architectures. Part (I of?) (Lecture Notes 5A)

NE Fundamentals of XAML and Microsoft Expression Blend

Transcription:

XAML Chapter 2 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon - 2014 Understanding XAML Developers realized long ago that the most efficient way to tackle complex, graphically rich applications is to separate the graphical portion from the underlying code. That way, artists can own the graphics, and developers can own the code. 1

Graphical User Interfaces Before WPF With traditional display technologies, there s no easy way to separate the graphical content from the code. The key problem with a Windows Forms application is that every form you create is defined entirely in C# code. Instead, artists are forced to take their content and export it to a bitmap format!!!!!!! Graphical User Interfaces Before WPF 1. Each graphical element (background, button, and so on) needs to be exported as a separate bitmap. 2. A fair bit of user interface logic needs to be embedded in the code by the developer. This includes button sizes, positioning, mouseover effects, and animations. The graphic designer can t control any of these details. 3. There s no intrinsic connection between the different graphical elements, so it s easy to end up with an unmatched set of images. 4. Bitmaps can t be resized without compromising their quality. 2

Graphical User Interfaces Before WPF WPF solves this problem with XAML. When designing a WPF application in Visual Studio, the window you re designing isn t translated into code. Instead, it s serialized into a set of XAML tags. When you run the application, these tags are used to generate the objects that compose the user interface. XAML Compilation The creators of WPF knew that XAML needed to not only solve the problem of design collaboration it also needed to be fast. WPF addresses this shortcoming with Binary Application Markup Language (BAML). BAML is really nothing more than a binary representation of XAML. 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. Not only is BAML significantly smaller, but it s also optimized in a way that makes it faster to parse at runtime. 3

XAML Basics The XAML standard is quite straightforward once you understand a few ground rules : 1. Every element in a XAML document maps to an instance of a.net class. The name of the element matches the name of the class exactly. For example, the element <Button instructs WPF to create a Button object. 2. As with any XML document, you can nest one element inside another. if you find a Button element inside a Grid element, your user interface probably includes a grid that contains a button inside. XAML Basics 3. 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. 4

XAML Basics This document includes only two elements the top-level Window element, which represents the entire window, and the Grid, in which you can place all your controls. Although you could use any toplevel element, WPF applications rely on just a few: Window Page (which is similar to Window but used for navigable applications) Application (which defines application resources and startup settings) XAML Basics Looking at the start tag for the Window element, you ll find several interesting attributes, including a class name and two XML namespaces. You ll also find the three properties shown here: 5

XAML Namespaces Clearly, it s not enough to supply just a class name. The XAML parser also needs to know the.net namespace where this class is located. For example, the Window class could exist in several places it might refer to the System.Windows.Window class. The xmlns attribute is a specialized attribute in the world of XML that s reserved for declaring namespaces. This snippet of markup declares two namespaces that you ll find in every WPF XAML document you create: XAML Namespaces http://schemas.microsoft.com/winfx/2006/xaml/prese ntation is the core WPF namespace. It encompasses all the WPF classes, including the controls you use to build user interfaces. In this example, this namespace is declared without a namespace prefix, so it becomes the default namespace for the entire document. In other words, every element is automatically placed in this namespace unless you specify otherwise. 6

XAML Namespaces http://schemas.microsoft.com/winfx/2006/xaml is the XAML namespace. It includes various XAML utility features that allow you to influence how your document is interpreted. This namespace is mapped to the prefix x. That means you can apply it by placing the namespace prefix before the element name (as in <x:elementname>). The Code-Behind Class XAML allows you to construct a user interface, but in order to make a functioning application, you need a way to connect the event handlers that contain your application code. The x namespace prefix places the Class attribute in the XAML namespace, which means this is a more general part of the XAML language. In fact, the Class attribute tells the XAML parser to generate a new class with the specified name. 7

The Code-Behind Class XAML allows you to construct a user interface, but in order to make a functioning application, you need a way to connect the event handlers that contain your application code. The x namespace prefix places the Class attribute in the XAML namespace, which means this is a more general part of the XAML language. In fact, the Class attribute tells the XAML parser to generate a new class with the specified name. this example creates a new class named Window1, which derives from the base Window class. The Code-Behind Class Visual Studio helps you out by automatically creating a partial class where you can place your eventhandling code. 8

Naming Elements In your code-behind class, you ll often want to manipulate controls programmatically. For example, you might want to read or change properties or attach and detach event handlers on the fly. To make this possible, the control must include a XAML Name attribute. Naming Elements the Name attribute tells the XAML parser to add a field like this to the automatically generated portion of the Window1 class: 9

Figure 2-1 shows an example with an automatic question answerer. Figure 2-1 shows an example with an automatic question answerer. The eight-ball window includes four controls: Grid (the most common tool for arranging layout in WPF), two TextBox objects, and a Button. 10

11

Simple Properties and Type Converters To bridge the gap between string values and nonstring properties, the XAML parser needs to perform a conversion. The conversion is performed by type converters The XAML parser follows two general steps to find a type converter. Simple Properties and Type Converters the Grid has a Background property that allows you to supply a brush that s used to paint the area behind the controls. 12

Simple Properties and Type Converters To define the gradient you want, you need to create a LinearGradientBrush object. Simple Properties and Type Converters However, it s not enough to simply create the LinearGradientBrush object you also need to specify the colors in that gradient. You do this by filling the LinearGradientBrush.GradientStops property with a collection of GradientStop objects. 13

Simple Properties and Type Converters Finally, you can fill the GradientStops collection with a series of GradientStop objects. Each GradientStop object has an Offset and Color property. Events Attributes can also be used to attach event handlers. The syntax for this is EventName= EventHandlerMethodName. This assumes that there is a method with the name cmdanswer_click in the code-behind class. The event handler must have the correct signature 14

Events The Full Eight-Ball Example 15