Xamarin Forms - No Property of name HorizontalTextAlignment found - xamarin

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.

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.

If you use previous xamarin.forms version , You should use 'XAlign' Property Instead. :)

Related

The Type "name" was not found - Xamarin

I am trying to implemenat a TabbedPage with Xamarin Forms. It is very similar to TabbedPage and Content pages are not showing
However I have a quick question as to how to include other xaml files from the MainPage.xam:
Here is my code:
MainPage:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Assignment"
x:Class="Assignment.MainPage">
<TabbedPage.Children>
<local:Alarm /> "The type 'local:Alarm' was not found. Verify that you are not missing..."
</TabbedPage.Children>
The above error is the only build error.
Alarm.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="Assignment.Droid.Resources.layout.Alarm">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Here is my project structure:
On the other link, I saw that he put his xaml files in the layout folder.
Is this the correct setup? I think I have missed something simple.
As Greggz mentions: move it to your shared project.
Then you will have to change your namespaces because that is what actually matters. In .NET land, it is customary that your namespace equals the path on your filesystem.
In you Alarm.xaml, change this line: x:Class="Assignment.Droid.Resources.layout.Alarm" to x:Class="Assignment.Alarm".
Then go into your code-behind, the Alarm.xaml.cs file and change the namespace there too. So change namespace Assignment.Droid.Resources.layout to namespace Assignment.
Since the XAML and the code-behind are implemented as a partial class, this needs to be in sync.

Badge count not displaying in Xamarin Forms

I am using this plugin for display badge count on tab. But some how it's not displaying. I think the problem with Naxam.Bottombar.plugin is used for display tabbar at the bottom in android. Because If I am using default TabbedPage then it works fine. How can I solve this?
I have followed all steps described in the badge plugin.
Code:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Graysons.Views.MenuPage"
xmlns:local="clr-namespace:Graysons.Customs"
xmlns:cc="clr-namespace:Graysons.Controls"
xmlns:vm="clr-namespace:Graysons.ViewModels"
xmlns:convertors="clr-namespace:Graysons.Convertors"
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
xmlns:resources="clr-namespace:Graysons.StringResources"
xmlns:plugin="clr-namespace:Plugin.Badge.Abstractions;assembly=Plugin.Badge.Abstractions"
Title="Menus" Icon="ic_menus.png" plugin:TabBadge.BadgeText="1" plugin:TabBadge.BadgeColor="Red" plugin:TabBadge.BadgePosition="PositionBottomRight" plugin:TabBadge.BadgeMargin="15"
Style="{StaticResource CustomTopBar}">
..............
</ContentPage>
Also Added Line for rendering badge count in AssemblyInfo.cs file.
Any help will be appreciated.
the following renderer to be added Platform specific folders, not in the main project AssemblyInfo.cs
[assembly: ExportRenderer(typeof(TabbedPage), typeof(BadgedTabbedPageRenderer))]
for eg: for iOS.
Sample.iOS/Properties/AssemblyInfo.cs
use this header
using Plugin.Badge.iOS;
then use the renderer
[assembly: ExportRenderer(typeof(TabbedPage), typeof(BadgedTabbedPageRenderer))]
for Android.
Sample.Android/Properties/AssemblyInfo.cs
use this header
using Plugin.Badge.Droid;
then use the renderer
[assembly: ExportRenderer(typeof(TabbedPage), typeof(BadgedTabbedPageRenderer))]

Overridding View for Different Platforms

I have a multiplatform app set up, so far it is working decently. My main issue though is I need to change the layout between IOS and Android. In my main solution I have a class called LocationView:
class LocationView : ContentView {
LocationView() {
InitializeView();
}
}
...and it's subsequent 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="Cabs.Views.LocationPage">
<ContentPage.Content>
<Label Text="I'm regular with a bunch of regular stuff" />
</ContentPage.Content>
</ContentPage>
For IOS, I need to change and subsequent controls (UIcontrols based, etc)
What is the correct way of doing this?
I know it has something to do w/ DI, not sure of the syntax. I tried the following:
[assembly: Dependency(typeof(LocationPage))]
It still isn't working
I try calling await Navigation.PushAsync(new DependencyService.Get<LocationPage>())
But I get a compile error
What is the correct procedure for this?
Thanks

Xamarin forms cannot access controls by it "x:Name"

Today i faced some issue. Please help me.
I created a cross platform application on IOS and Android. So i trying to access my MainPage controls form .cs file but i can't. Here is provided code.
MainPage.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"
xmlns:local="clr-namespace:Movies"
x:Class="Movies.MainPage">
<TableView x:Name="mainTable">
<TableSection>
<ViewCell>
<ViewCell.View>
<Label Text="Hello"></Label>
</ViewCell.View>
</ViewCell>
</TableSection>
</TableView>
</ContentPage>
MainPage.xaml.cs
using Xamarin.Forms;
namespace Movies
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
mainTable.
}
}
}
https://i.imgur.com/OKO3yYc.png
Project runs successfully.
https://i.imgur.com/ondjVkP.png
I tried rebuild and even restore VS17 in VS installer.
this.mainTable doesn't work either.
Click on the .XAML file, select Properties.
See a Property called Custom Tool. Change its value from MSBuild:Compile to MSBuild:UpdateDesignTimeXaml or if it is blank set it to MSBuild:UpdateDesignTimeXaml.
This will solve the problem.
Build the project once,then you can access the name in .cs file.

Type not found in xmlns build error when using third party control library

I added a third party control in my Xamarin forms project through nuget. I added a xmlns to my xaml for the library, but when I build I get the error: Type flv:FlowListView not found in xmlns clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView;assembly=DLToolkit.Forms.Controls.FlowListView
Using the following 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"
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView;assembly=DLToolkit.Forms.Controls.FlowListView"
x:Class="FScruiser.XF.Pages.Page1">
<ContentPage.Content>
<flv:FlowListView>
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<ViewCell>
<Label Text="text"/>
</ViewCell>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
</ContentPage.Content>
</ContentPage>
Try this:
clr-namespace:DLToolkit.Forms.Controls
instead of
clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView
So, the full namespace definition is this:
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
Edit: You can also see it in action here on GitHub, in one of the samples.

Resources