Note that this is a rather personal opinion and the recommendation for XAML or C# might change with future Xamarin. In the following, we want to give a tiny example on how to create an app using Xamarin and an XAML layout description. Forms solution, we add a new “Forms Content Page Xaml” named “Label Page” to the shared project.
This generates two files: “Label Page.xaml” with the XAML code as well as a nested “Label cs” with corresponding C# code. The actual page content is framed by a On of the most powerful features of Xamarin.
In the next section we will describe in more detail, how to work with the screen size in the cross-platform code.
Forms is its capability of working with natively implemented extensions of its default elements.
If we wish to modify a visual element in some way or add new properties, we can derive a custom renderer with a platform-specific implementation. But in the next step we will override the corresponding i OS and Android renderers with a custom implementation considering all newly introduced properties. It contains information like color, stroke with or whether we want to use anti-aliasing.
The visual appearance will be almost identical, but the implementation will be conceptually different.
The The screenshot shows an overview of the final result.
Besides specifying the and horizontal spacing we pre-compute the width of the block with name, subject and body.
To fill the available horizontal space completely, we need to refer to the screen width.
In the following example we will create a new UI element showing a red ball that can be moved around the screen. The ball is red and centered using the position (0.5, 0.5).
(Since we will exchange coordinates between shared and platform-specific code, we would need to convert between device-independent and -dependent pixels.
This can involve a custom visualization or even custom gesture-based user interaction. The latter is a technique to avoid “staircases” when drawing sloped lines and shapes, which generally yields more visually pleasing results at the cost of slightly more computing time.