Sunday, October 15, 2017

XAML support

Xamarin.Forms also supports XAML (pronounced “zammel” to rhyme with “camel”), the XML-based Extensible Application Markup Language developed at Microsoft as a general-purpose markup language for instantiating and initializing objects. XAML isn’t limited to defining initial layouts of user interfaces, but historically that’s how it’s been used the most, and that’s what it’s used for in Xamarin-.Forms.

Here’s the XAML file for the program whose screenshots you’ve just seen:

xmlns:x="" x:Class="PlatformVisuals.PlatformVisualsPage" Title="Visuals">
<StackLayout Padding="10,0">
<Label Text="Hello, Xamarin.Forms!" FontSize="Large" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Button Text = "Click Me!" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Switch VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Slider VerticalOptions="CenterAndExpand" />
<ToolbarItem Text="edit" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="edit.png" Android="ic_action_edit.png" WinPhone="Images/edit.png" />
<ToolbarItem Text="search" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="search.png" Android="ic_action_search.png" WinPhone="Images/" />
<ToolbarItem Text="refresh" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="reload.png" Android="ic_action_refresh.png" WinPhone="Images/refresh.png" />
<ToolbarItem Text="explore" Order="Secondary" />
<ToolbarItem Text="discover" Order="Secondary" />
<ToolbarItem Text="evolve" Order="Secondary" />

Unless you have experience with XAML, some syntax details might be a little obscure. But even so, you can see the Label, Button, Switch, and Slider tags. In a real program, the Button, Switch, and Slider would probably have event handlers attached that would be implemented in a C# code file. Here they do not. The VerticalOptions and HorizontalOptions attributes assist in layout.

Source of Information : Creating Mobile Apps with Xamarin.Forms

No comments: