Sunday 5 July 2015

Windows App Development (win 8.1) - #1

Before starting windows App Development we must know about XAML.

         XAML (Extension Application Markup Language) is a XML based Language Developed by Microsoft.
XAML forms a User Interface markup language to define User Interface  elements, Data Biding, events and other features.

XAML for Windows Mobile:
         XAML is similar to HTML, its frame work Code name is “Jupiter” for windows run-time. XAML is a part of the windows run-time programming model that forms the backbone of windows store apps (formally known as Metro style ( or) Immersive) for the windows 8, 8.1 and Phone 8.1 operating System. It enables Declaring user interface using XAML Technology.
         XAML is really just XML, Normally HTML is used to design Web pages and XML is more powerful than HTML. In XML we can define elements and attributes to suite our needs. We are using XML to share Information between Devices, and application configurations but XAML is used for User Interface design in windows app development. In windows app XAML is Creating instance for Classes and set the values of the properties in C# file. XML and HTML are not case sensitive but XAML is Case sensitive Just see the following small example. For Button Control how I we in XAML.

<Button x:Name=”TestClick”
Content="Button" 
HorizontalAlignment="Left"
Margin="144,131,0,0" 
VerticalAlignment=”Top”
Click=”MyButton_Click”
Width=”200”
Height=”100”
Background=”Red”/>

These XAML Code is equal to Following Code in Code behind

Protected override void OnNavigated(NavigationEventArgs e)
{
Button myButton=new Button();
myButton.Name=”TestClick”;
myButton.Content=”Button”;
myButton.Width=”200”;
myButton.Height=”100”;
myButton.HorizontalAlignment=Windows.UI.Xaml.HorizontalAlignment.Left;
myButton.VerticalAlignment=Windows.UI.Xaml.VerticalAlignment.Top;
myButton.Background=new SolidColorBrush(Colors.Red);
myButton.Click += MyButton_Click;

<Grid_Name>.children.Add(myButton);
}

         Here XAML Button Control is Instance for the Button class in C#. Here have you seen the Code behind for single Button Control we wrote 10 lines of code, But by using XAML we wrote the same Code in single line  only. Suppose if our page have more than 20 controls if we use the XAML it is just 20 lines of code only but if we use same Code in C# Code behind it take single control for eacdh line. And we will easily defined the Controls in XAML. 

         Here have observe the deference between XAML and C#. For properties VerticalAlignment, Background, HorizontalAlignment properties how we wrote in XAML and C#. XAML parser will Convert HorizontalAlignment property value "Left" to Windows.UI.Xaml.HorizontalAlignment.Left, if you try myButton.HorizontalAlignment="Left" then C# Compiler will throw the Error.

         Have you remember XAML is Case Sensitive if you type HorizontalAlignment property value "left" then we will get the Compilation Error because XAML can't find the exact match for  Windows.UI.Xaml.HorizontalAlignment.Left. You will know more about XAML when the real Development Start.

No comments:

LinkWithin

Related Posts Plugin for WordPress, Blogger...