Writing XAML Application On MAC OS



XAML applications can be developed on Mac as well. On Mac, XAML can be used as iOS and Android applications. To setup the environment on Mac, go to www.xamarin.com. Click on Products and select the Xamarin Platform. Download Xamarin Studio and install it. It will allow you to develop applications for the various platforms.

XAML – C# Syntax

In this chapter, you will learn the basic XAML syntax/rules to write XAML applications. Let’s have a look at a simple XAML file.

<Window x:Class = "Resources.MainWindow" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "MainWindow" Height = "350" Width = "525"> 
	
   <Grid> 
         
   </Grid> 
</Window> 

As you can see in the above XAML file, there are different kinds of tags and elements. The following table briefly describes all the elements.

Sr.No Elements & Description
1

<Window

It is the opening object element or container of the root.

2

x:Class="Resources.MainWindow"

It is the partial class declaration which connects the markup to the partial class code behind defined in it.

3

xmlns

Maps the default XAML namespace for WPF client/framework

4

xmlns:x

XAML namespace for XAML language which maps it to x: prefix

5

>

End of object element of the root.

6

<Grid>

</Grid>

Starting and closing tags of an empty grid object.

7

</Window>

Closing the object element

Syntax Rules for Object Element

Syntax rules for XAML is almost similar to XML. If you take a look at an XAML document, then you will notice that actually it is a valid XML file. However, an XML file cannot be a valid XAML file. It is because in XML, the value of the attributes must be a string, while in XAML, it can be a different object which is known as Property element syntax.

  • The syntax of an Object element starts with a left angle bracket (<) followed by the name of the object, e.g. Button.

  • Define some Properties and attributes of that object element.

  • The Object element must be closed by a forward slash (/) followed immediately by a right angle bracket (>).

Example of simple object with no child element −

<Button/>

Example of object element with some attributes −

<Button Content = "Click Me" Height = "30" Width = "60"/> 

Example of an alternate syntax to define properties (Property element syntax) −

<Button> 
   <Button.Content>Click Me</Button.Content> 
   <Button.Height>30</Button.Height> 
   <Button.Width>60</Button.Width> 
</Button>

Example of Object with Child Element − StackPanel contains Textblock as child element

<StackPanel Orientation = "Horizontal"> 
   <TextBlock Text = "Hello"/> 
</StackPanel> 
Advertisements