Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Closer Look at XAML

DZone's Guide to

A Closer Look at XAML

· Mobile Zone
Free Resource

Get gorgeous, multi-touch charts for your iOS application with just a few lines of code.

I’ve seen people writing code rather in the XAML page than in the C# code page. Things seem to be easier, faster.

So I figured, it might be time to take a closer look.

XAML (Extensible Application Markup Language) is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects.

When creating a new project (or opening an existing one) the first thing I see in Visual Studio is the design pane on the left side and the XAML pane on the right side. The design pane provides a fast and convenient way to arrange controls and set properties visually. Everything that goes on in the design pane has one purpose. And that is to create code in the XAML window. The XAML is what actually gets compiled into a .NET assembly, a .dll file that ultimately gets packaged up in a SAP file.

To have an example I just created a new project. When I drag a button control to my design surface, something happens in the XAML pane. Some code is being generated that defines the button:

  1. <Button Content="Button"
  2.         Height="72"
  3.         HorizontalAlignment="Left"
  4.         Margin="9,6,0,0"
  5.         Name="button1"
  6.         VerticalAlignment="Top"
  7.         Width="160" />

 

That’s a whole block of code without me even having to write it. Now I want to create a new button without dragging it to my design pane. I am writing code in XAML:

  1. <Button Content="Click Me"
  2.         Height="72"
  3.         HorizontalAlignment="Left"
  4.         Margin="100,100,0,0"
  5.         Name="button2"
  6.         VerticalAlignment="Top"
  7.         Width="160" />

 

What happens now, is that this in XAML created button also appears in my design pane:

xaml1

The first button was dragged and dropped, the second one was created in XAML.

Since I don´t have a click event for my buttons, the C# code for my buttons just refers to my XAML pane:

  1. namespace XamlDesigner
  2. {
  3.     public partial class MainPage : PhoneApplicationPage
  4.     {
  5.         // Constructor
  6.         public MainPage()
  7.         {
  8.             InitializeComponent();
  9.         }

 

Basically what I learned is that if I really want to develop applications for Windows Phone 7, I have to continue learning C#, but also XAML. Well, so far that doesn’t seem too difficult.

 

To be continued…



Source:  http://andreahaubner.blog.com/2011/02/18/looking-closer-at-xaml/

.Net developers: use Highcharts, the industry's leading interactive charting library, without writing a single line of JavaScript.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}