.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Understanding In and Out of XAML in WPF

Posted By:Vishal Nayan       Posted Date: September 18, 2011    Points: 200    Category: WPF    URL: http://www.dotnetspark.com  

Understanding In and Out of XAML in WPF

Understanding In and Out of XAML in WPF

1. What is XAML? Extensible Application Markup Language and pronounced "zammel" is a markup language used to instantiate .NET objects. Although XAML is a technology that can be applied to many different problem domains, its primary role in life is to construct WPF user interfaces.

If we're a graphic designer, that tool is likely to be a graphical design and drawing program such as Microsoft Expression Blend. If we're a developer, we'll probably start with Visual Studio.

2. Why to learn XAML: Understanding XAML is critical to WPF application design. WPF applications are quite different from Windows Forms applications in this respect-with Windows Forms applications, we could safely ignore the automatically generated UI code, while in WPF applications the XAML often takes center stage. Important task they perform are below

a. Wiring up an event handler: Attaching event handler in the most cases, for example Click on Button is easy to do in visual studio. However once we understand how events are wired up in XAML,we'll be able create more sophisticated connections.


b. Defining resources: Resources are the object which once we define in XAML can be re-used in the various places inside markup. Resources allow us to centralize and standardize formatting, and create nonvisual objects such as templates and animations.

c. Defining control template: WPF controls are designed to be lookless, which means we can substitute our custom visuals in place of the standard appearance. To do so, we must create our own control template, which is nothing more than a block of XAML markup

d. Writing data binding expressions: data binding allows us to extracts data from a object and display it in a linked element. To setup this we can add a data binding expression in XAML.

e. Defining animation: Animations are a common ingredient in XAML applications. Usually, they're defined as resources, constructed using XAML markup, and then linked to other controls (or triggered through code).

3. Life before XAML: With traditional display technologies, there's no easy way to separate the graphical content from the code. The key problem with Windows Forms application is that every form we create

Is defined entirely in C# code. As we drop controls onto the design surface and configure them, Visual Studio quietly adjusts the code in the corresponding form class. Sadly, graphic designers don't have any tools that can work with C# code.

Then solution to above problem was that the designer forced to take their content and export it to a bitmap format. These bitmaps can then be used to skin windows, buttons, and other controls. This approach works well for straightforward interfaces that don't change much over time, but it's extremely limiting in other scenarios.

Even if the interface is designed from scratch by a graphic designer, we'll need to re-create it with C# code. Usually, the graphic designer will simply prepare a mock-up that we need to translate painstakingly into our application.

Solution to above issue is XAML: When designing a WPF application in Visual Studio, the window we're designing isn't translated into code. Instead, it's serialized into a set of XAML tags. When we run the application, these tags are used to generate the objects that compose the user interface.

4. Type of XAML: The way XAML is been used in reference with are many, which is nothing but is an all-purpose XML-based syntax for representing a tree of .NET objects and these objects can be button in a window or a custom class we have defined. However XAML could be used on the other platform to re-present non .NET objects.

Below I have discussed about subsets of XAML

a. WPF XAML: encompasses the elements that describe WPF content, such as vector graphics, controls, and documents

b. XPS XAML: is the part of WPF XAML that defines an XML representation for formatted electronic documents.

c. Silverlight XAML: is a subset of WPF XAML that's intended for Silverlight applications. Silverlight is a cross-platform browser plug-in that allows us to create rich web content.

d. WF XAML: encompasses the elements that describe Windows Workflow Foundation.


5. Understanding XMAL compilation:  Solving the pain for designed cannot be a sole reason to be happy about XAML, well it also needs to be fast in performance. XAML achieves this with BAML (binary application markup language), which is binary representation of XMAL.

What happen when we compile XAML in visual studio, all XAML is converted into BAML and that BAML is then embedded as resource inside the final DLL or EXE assembly. BAML is tokenized, which means lengthier bits of XAML are replaced with shorter tokens. Not only is BAML significantly smaller, it's also optimized in a way that makes it faster to parse at runtime.

So do we require or is it must that this compilation happens, well no. because there might be an scenario where it is required  some of the user interface to be supplied just in time, so here possible to use XAML without compiling it.


6. Knowing XAML Skelton:


a. 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

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend