What is the difference between Xamarin.Form’s layout options?

In Xamarin.Forms every View has the two properties HorizontalOptions and VerticalOptions. Both are of type LayoutOptions and can have one of the following values:

  • LayoutOptions.Start
  • LayoutOptions.Center
  • LayoutOptions.End
  • LayoutOptions.Fill
  • LayoutOptions.StartAndExpand
  • LayoutOptions.CenterAndExpand
  • LayoutOptions.EndAndExpand
  • LayoutOptions.FillAndExpand

Apparently it controls the view’s alignment on the parent view. But how exactly is the behavior of each individual option? And what is the difference between Fill and the suffix Expand?


The structure LayoutOptions controls two distinct behaviors:

  • Alignment:

    How is the view aligned within the parent view?

    • Start: For vertical alignment the view is moved to the top. For horizontal alignment this is usually the left-hand side. But note, that on devices with right-to-left language setting this is the other way around, i.e. right aligned.
    • Center: The view is centered.
    • End: Usually the view is bottom or right aligned. On right-to-left languages, of course, it is left aligned.

    • Fill: This alignment is slightly different. The view will stretch across the full size of the parent view. If the parent, however, is not larger then its children, you won’t notice any difference between those alignments. Alignment only matters for parent views with additional space available.

  • Expansion:

    Will the element occupy more space if available?

    • Suffix Expand:

      If the parent view is larger than the combined size of all its children, i.e. additional space is available, then the space is proportioned amongst child views with that suffix. Those children will “occupy” their space, but do not necessarily “fill” it. We’ll have a look on this behavior in the example below.

    • No suffix: The children without the Expand suffix won’t get additional space, even if more space is available. Again, if the parent view is not larger than its children, the expansion suffix does not make any difference as well.


To demonstrate the effect of different LayoutOptions, we create a tiny example app. It consists of a gray StackLayout with some padding and some spacing between its child elements.

static readonly StackLayout stackLayout = new StackLayout {
    BackgroundColor = Color.Gray,
    Padding = 2,
    Spacing = 2,

The constructor of our App adds eight child elements before assigning the StackLayout to the MainPage. Note that we use a device-dependent padding for the MainPage to avoid elements being overlaid by the iOS status bar.

public App()
    AddElement("Start", LayoutOptions.Start);
    AddElement("Center", LayoutOptions.Center);
    AddElement("End", LayoutOptions.End);
    AddElement("Fill", LayoutOptions.Fill);
    AddElement("StartAndExpand", LayoutOptions.StartAndExpand);
    AddElement("CenterAndExpand", LayoutOptions.CenterAndExpand);
    AddElement("EndAndExpand", LayoutOptions.EndAndExpand);
    AddElement("FillAndExpand", LayoutOptions.FillAndExpand);

    MainPage = new ContentPage {
        Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0),
        Content = stackLayout,

The method AddElement creates a new Label with different text and corresponding layoutOption. Its text is centered horizontally and vertically using the two properties HorizontalTextAlignment and VerticalTextAlignment.

Furthermore, it adds a flat yellow BoxView. This will serve as a visual separator between the space occupied by the white labels.

static void AddElement(string text, LayoutOptions layoutOption)
    stackLayout.Children.Add(new Label {
        Text = text,
        BackgroundColor = Color.White,
        HorizontalTextAlignment = TextAlignment.Center,
        VerticalTextAlignment = TextAlignment.Center,
        HorizontalOptions = layoutOption,
        VerticalOptions = layoutOption,
        WidthRequest = 160,
        HeightRequest = 25,
    stackLayout.Children.Add(new BoxView {
        HeightRequest = 1,
        Color = Color.Yellow,

The screenshot shows the resulting layout. We make the following observations:

  • The different alignment is only visible if there is space available. If the stackLayout would not fill the page, we might not be able to see a difference between elements with options Start or StartAndExpand.

  • Additional space is evenly proportioned amongst all labels with Expand suffix. To see this more clearly we added yellow horizontal lines – actually flat BoxViews – between every two neighboring labels. Labels with more space than their requested height do not necessarily “fill” it. In this case the actual behavior is controlled by their alignment. E.g. they are either aligned on top, center or label of their space or fill it completely.

  • If there is space available and no other expanding element – like in the horizontal direction – the alignment controls the element’s position even if it is not expanding, like the first four labels.


Android required permissions

In Visual Studio 2015 if you checked same permissions on your project properties and when reopen it, your checks are disappeared, you have two ways:

  1. Is the manifest file marked as 'read only' in Windows Explorer? You have to select the Properties directory and un-tick 'read only' for the entire folder.
  2. Add manually in AndroidManifest.xml file same new rows:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-sdk android:minSdkVersion="15" />
      <application android:label="$safename$">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" 
                      android:value="yourcode" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
      <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Happy coding!

Introducing the UWP Community Toolkit

Recently, Microsoft released the Windows Anniversary Update and a new Windows Software Developer Kit (SDK) for Windows 10 containing tools, app templates, platform controls, Windows Runtime APIs, emulators and much more, to help create innovative and compelling Universal Windows apps.

Today, we are introducing the open-source UWP Community Toolkit, a new project that enables the developer community to collaborate and contribute new capabilities on top of the SDK.

We designed the toolkit with these goals in mind:

  1. Simplified app development: The toolkit includes new capabilities (helper functions, custom controls and app services) that simplify or demonstrate common developer tasks. Where possible, our goal is to allow app developers to get started with just one line of code.
  2. Open-Source: The toolkit (source code, issues and roadmap) will be developed as an open-source project. We welcome contributions from the .NET developer community.
  3. Alignment with SDK: The feedback from the community on this project will be reflected in future versions of the Windows SDK for Windows 10.


All Windows 10 PCs will get Windows Holographic access next year


Windows 10 users will be able to dive into mixed reality starting next year, with an update planned that can let any “mainstream” Windows 10 PC run the Windows Holographic shell the company first revealed in January 2015.

The update will allow users to multi-task in mixed reality environments, which combine traditional 2D Windows 10 apps with immersive, 3D graphical environments. These will be enabled via a range of “6 degrees of freedom devices,” input devices that add positional tracking to other more traditional forms of input, like clicking and pointing.

The Windows team is trying to make this more broadly available, too, thanks to support for a range of Windows 10 PCs that don’t necessarily need the specs required to run full-scale VR today. As an example, Microsoft presented a video of Windows 10 Holographic running at 90 FPS on an Intel NUC, a tiny desktop PC that’s not super expensive and included integrated Intel graphics.

While it’s still unlikely that we’ll all be doing our average desk workflow of spreadsheets and slide presentation in mixed reality any time soon, it’s good to see Microsoft set a timeline for public availability of a feature which, at launch, seems like it had the potential to become vaporware rather than a shipping product.

Intel and Microsoft are also building a specification for mixed reality PCs, as well as head-mounted displays that let users experience the mixed reality operating environment. The public release of the spec is planned for an upcoming Windows hardware develop conference in Shenzhen this December.

Custom ContextAction with Xamarin Forms

I using a Xamarin Forms ListView and I want to enable or disable the Context Actions based on a certain binding or in the code behind.

The way I found is to use BindingContextChanged in a ViewCell. I show you an example

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
      <ListView x:Name="listDictionaries" 
                ItemsSource="{Binding DictionariesList}" 
                IsVisible="{Binding ShowList}"
                RefreshCommand="{Binding Refresh}" 
                IsRefreshing="{Binding IsBusy, Mode=OneWay}">
            <ViewCell BindingContextChanged="OnBindingContextChanged">
                  <Grid Padding="10" ColumnSpacing="10">
                      <RowDefinition Height="*" />
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="*" />
                    <Label Text="{Binding Name}" FontSize="Large" 
                           Grid.Row="0" Grid.Column="0" />
                    <Label Text="{Binding Description}" FontSize="Small" 
                           Grid.Row="1" Grid.Column="0" />

Then you insert in the code the following code:

/// <summary>
/// Called when binding context changed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> 
/// instance containing the event data.</param>
private void OnBindingContextChanged(object sender, EventArgs e) {

    if (BindingContext == null)

    ViewCell theViewCell = ((ViewCell)sender);
    var item = theViewCell.BindingContext as DictionaryModel;

    if (item != null) {
        MenuItem mn = new MenuItem();
        mn.Clicked += Menu_Clicked;
        mn.Text = "Delete";
        mn.IsDestructive = true;
        mn.CommandParameter = item.Id;

private async void Menu_Clicked(object sender, EventArgs e) {
    var mi = ((MenuItem)sender);

Happy coding!

Microsoft releases its Common Data Model database to testers

Microsoft has made a promised public preview of its Common Data Model (CDM) entity database available to testers. CDM is at the heart of the coming Microsoft Dynamics 365 bundle.


Microsoft made the promised public preview of its Common Data Model database available on August 8.

The Common Data Model, which Microsoft describes as "an out-of-box business database for storing and managing business entities," is at the center of its PowerApps service for building custom business apps and the coming Dynamics 365 ERP/CRM cloud bundle.

CDM can be used today as a business database for flows created with Microsoft's Flow event-automation tool. CDM can provide access to standard entities, plus allow developers to build custom entities. Microsoft is providing some templates to help users get started.

Users will be able to use CDM to collect data, such as Tweets or RSS items. They also can import and export data from services like Dynamics CRM, Salesforce.com, Excel, and Microsoft's SQL database (cloud and on-prem). They also have the option to use CDM to build and store history/status of pending approvals.

The CDM is meant to provide a database of entities that are common across industry domains, like Sales, Purchase, Customer Service, and Productivity. These entities will connect to Microsoft's first-party business applications, as well as third-party and customer-developed apps.

The entities in CDM will support data types like Address, Email, Currency, Invoice and Order Auto Numbering, images, geographic locations, and more. They'll be implemented using the latest SQL Server data types.

The CDM will be at the heart of Microsoft's Dynamics 365 cloud bundle, the first pieces of which will be available this fall.

Android.Content.Res.Resources+NotFoundException: Resource ID #0x0

I've just created a simple MasterDetailPage and in the code I inserted an icon for the left page with:

public MainPage() {

    BackgroundColor = Color.FromHex("#007acc");
    Icon = "settings.png";

I tried to deploy my app on an Android emulator but I can't deploy it because Android.Content.Res.Resources+NotFoundException: Resource ID #0x0.

I checked everthing and evething seemed fine. The problem is the icon!

You have to remove Icon from the code and in the XAML page type the following code:

    <OnPlatform x:TypeArguments="FileImageSource">

Happy coding!

How to deploy an Universal Windows Project on real device mobile?

I'm trying to debbuging my app on real device (lumia 830 with windows 10 mobile 10.0.10581.0) Developer Mode is ON on both devices (mobile and PC), but when I'm deploying my app on my device I've got an error (DEP6100 and DEP6200). Howevere i can easily emulate on emulators and my PC, couldn’t understand whats the problem.

I googled a bit and I discovered how to resolve the problem.


  • Create a Registry Key in: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SirepClient] (Probably you will need to create it)
  • Create a dword with name "DisableProtocol3" and value 00000001
  • Restart Visual Studio and try deploying the solution back again.

It's a provisional solution meanwhile a patch is included in Windows 10 mobile. We will have to consider deleting this key after that.

If you want to inspect your device, connect your device via USB and open a browser and type

And you can watch your device in action!

Windows 10 Device – Home


Windows 10 Device – App Manager


Windows 10 Device – File Explorer


Windows 10 Device – Processes


Windows 10 Device – Performances (in real time!)


Windows 10's Anniversary Update is now available


Microsoft's Windows 10 Anniversary Update is here and ready to download. The software maker first started testing its Anniversary Update back in December, and now all Windows 10 users get to experience the new features and improvements free of charge. Chief among them is a new Windows Ink feature. Microsoft has supported inking in Windows for years, but Windows Ink is a dedicated hub designed for devices like the Surface Pro 4, and other 2-in-1s with styluses. Windows Ink will work with your fingers, for doodling and inking on screenshots, but it will obviously work better with a dedicated stylus.

Windows 10 Anniversary Update also includes a number of UI improvements to the Start menu, notification center, taskbar, and overall dark theme. Microsoft is also tweaking Cortana to allow the digital assistant to work on the lock screen and answer queries. If you're a fan of Microsoft's Edge browser, it's also getting extension support today. Extensions like LastPass, 1Password, AdBlock, and EverNote are all available, and more should arrive in the Windows Store in the coming months. Windows 10 Anniversary Update is available from Windows Update immediately, an ISOs are also available (or an easy clean install tool) if you're interested in clean installing the update to your system.

Visual Studio updates Xamarin

When you open Visual Studio 2015 and there is a pop windows to invite you to click on it for updating Xamarin and you click, nothing happends. There is a bug but clicking the update available popup was fixed in one of the recent releases. You can manually update in the Options menu under Tools.

As for the errors, I get those all the time. Support packages can often be a problem. Update to the latest XF package. Try deleting bin, obj, and the contents of packages folders and rebuild.




Planet Xamarin

Planet Xamarin


<<  November 2017  >>

View posts in large calendar

Month List