Friday, 22 January 2016

Type Converter in XAML

In this , I'm going to show you how XAML Works in background and makes UI designing very easy for us .
we're going to discuss about Automatic Type converters in XAML.

whenever you make some control in XAML you set its properties. For example in following screen shot we are making a button in XAML and setting its properties like
  • Name 
  • Horizontal Alignment
  • Margin
  • Background
  • Vertical Alignment                 
  • Horizontal Alignment
  • and
  • Background Color
    etc , you are shown a list of given option through Intellisense like below.
      
  • So you have limited options as shown in above screenshot. you've to select 1 position from 4 given options . These options are infect enums.




have you ever noticed that when you type in for setting the properties like ,
Now I'm going to show you the alternate way to set properties using C# syntax. To make a button from C# write following code in Page Load Event in program.

when you make a control from C# code. You've to set all of its properties in code. In this case we've set its
  • HorizontalAlignment
    and
  • Background
 properties. You selected the background color and Horizontal Alignment from a strongly typed enumeration for the button. So the question is ! How these properties are mapped to strongly typed enumeration, when you type a string which is "left" in the case of alignment property and "Red" in case of color selection.
Answer is ! XAML parser does this job.
   XAML parser convert string value into a strongly typed version of that value.
so when you set the properties like < horizontalAllignment = "Left" >  , the string "Left" will be mapped to the strongly typed enum by the XAML parser.

No comments:

Post a Comment