Search code examples
xamarinxamarin.formsxamarin-studio

Xamarin Forms - No Property of name HorizontalTextAlignment found


New to Xamarin so following a simple intro/tutorial (here)to Xamarin forms (using Xamarin Studio on a Mac). Per instructions, I entered the following into the xaml file (HelloXamlPage.xaml):

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage    xmlns="http://xamarin.com/schemas/2014/forms" 
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                x:Class="XamForms.HelloXamlPage"
                Title="Hello XAML Page"
                Padding="10, 40, 10, 10">

  <Label Text="Hello, XAML!"
         VerticalOptions="Start"
         HorizontalTextAlignment="Center"
         Rotation="-15"
         IsVisible="true"
         FontSize="Large"
         FontAttributes="Bold"
         TextColor="Aqua" />

</ContentPage>

The code-behind file (HelloXamlPage.xaml.cs) is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace XamForms
{
    public partial class HelloXamlPage : ContentPage
    {
        public HelloXamlPage ()
        {
            InitializeComponent ();
        }
    }
}

When I try to build and run it for Android or iOS I get this error: Xamarin.Forms.XamlParseException - No Property of name HorizontalTextAlignment found. Checking the documentation, it's definitely a valid property. Any help/ideas appreciated.


Solution

  • You need to be using one of the latest versions of Xamarin Forms. Upgrade your Xamarin Forms NuGet package to the latest 2.0.1 and you will get the property.

    2.0.0 (or the 1.5.2 pre releases) were the first to have the property.