Xamarin forms maps error :"Not compatable code running - c#

I am trying to create a simple map page using Xamarin forms maps checking this project only on Andorid.
I Installed the Xamarin forms map. and added the Xaml Below,
in addition I've added the in the Android manifest XML all the relavent
premiisions and Key.
however I am getting this error:Not compatable code running the selected debug engine does not support any code executing on the current thread
would appericate any help
<?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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="MashamApp.mapPage" Title="מפה" >
<ContentPage.Content>
</ContentPage.Content>
<Grid>
<maps:Map x:Name="LocationMap"
IsEnabled="True" IsVisible="True"
MapType="Hybrid"
HasScrollEnabled="True"
HasZoomEnabled="True"
HeightRequest="480"
WidthRequest="480"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" >
</maps:Map>
</Grid>

As pointed out by Yuri, a content page should only have a single view or layout.
Change your page to look like this:
<?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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="MashamApp.mapPage" Title="מפה" >
<Grid>
<maps:Map x:Name="LocationMap"
IsEnabled="True" IsVisible="True"
MapType="Hybrid"
HasScrollEnabled="True"
HasZoomEnabled="True"
HeightRequest="480"
WidthRequest="480"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" >
</maps:Map>
</Grid>
</ContentPage>
You don't even need the Grid unless you are going to add more views inside it.
See here for more details

Related

Error: Unknown type 'ContentPage' in XML namespace 'http://xamarin.com/schemas/2014/forms' MyAPP!!!!!!!.UWP

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyAPP_______.UWP"
x:Class="MyAPP_______.UWP.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
Outputs 3 errors, I wanted to test the work of xamarin, and the emulator, I don't know what to do, I'm working with xamarin for the first time.
1.Unknown type 'ContentPage' in XML namespace 'http://xamarin.com/schemas/2014/forms' MyAPP!!!!!!!.UWP
2. Unknown type 'Label' in XML namespace 'http://xamarin.com/schemas/2014/forms' MyAPP!!!!!!!.UWP
3.Unknown type 'StackLayout' in XML namespace 'http://xamarin.com/schemas/2014/forms' MyAPP!!!!!!!.UWP

Why does my lottie animation doesn't show in Xamarin Forms?

I followed a tutorial and for some reason my lottie animation is not being shown when I test on Android device.
Package Com.Airbnb.Lottie.Forms was added to all app projects (it's crossplatform)
Then added Com.Airbnb.Android.Lottie to the Android app (first I tried without it, didn't work either)
This is the code
<?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:lottie="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
x:Class="AppWasher.MainPage">
<StackLayout>
<lottie:AnimationView
x:Name="animationView"
Animation="26617-ogad.json"
RepeatMode="Restart"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
WidthRequest="300"
HeightRequest="300"/>
</StackLayout>
</ContentPage>
This is the guide lottie provides
<forms:AnimationView
x:Name="animationView"
Animation="LottieLogo1.json"
AnimationSource="AssetOrBundle"
Command="{Binding ClickCommand}"
RepeatCount="3"
RepeatMode="Restart"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
I tried using all those properties too, same result.
I'm testing on Android 9.0 version
Also json files were added to the assets folder in the android project and build action is set to AndroidAsset
It works for me after i change the android Target Framework version to Android 10.0.
And i found the latest Lottie nuget depends on AndroidX.

Why I get This error? Can't Load Types From

I was in my project and suddenly, this error appeared:
Can't load types from xmlns http://schemas.microsoft.com/winfx/2006/ xaml/presentation TaskX.UWP C:\Users\M\source\repos\TaskX\TaskX\TaskX\New.xaml
This is my full code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="TaskX.New"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TaskX"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<StackLayout>
<Label Text="Hello World"/>
</StackLayout>
</ContentPage>
If you are renaming pages, you need to make sure the xaml class is pointing to your backing class
Xaml
<ContentPage
x:Class="YourNameSpace.SomeAwesomeNamePage"
Code Behind
public partial class SomeAwesomeNamePage : ContentPage

Xamarin.Forms TabbedPage

I have a little problem in this project. This is my tabbed page declaration:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:JacksCurrencyConverter;assembly=JacksCurrencyConverter"
x:Class="JacksCurrencyConverter.StartPage"
x:Name="Children"
HeightRequest="10"
WidthRequest="10">
<TabbedPage.Children>
<local:MainPage Icon="currency.png" Title="Exchange"/>
<local:FavouritesPage Icon="favourites2.png" Title="Favourites"/>
<local:MainPage Icon="statistics2.png" Title="Info"/>
</TabbedPage.Children>
</TabbedPage>
Then this is how it looks in iOS and Android:
iOS:
Android:
How could I reduce the empty blue space shown in the tabbpage on Android?
Blue space to reduce:
Sorry, I need at least 10 reputation to post images.
The reason you are getting this space is because you have a navigation page wrapped on your normal content page
Doing something like this will remove your space:
Mainpage= new StartPage();
Add horizontal and vertical option and this should fix the top empty space.
<TabbedPage>
<ContentPage Title="Exchange"
HorizontalOptions="StartAndExpand"
VerticalOptions="Center" Padding="0">
<local:MainPage Icon="currency.png" Title="Exchange"/>
</ContentPage>
<ContentPage Title="Favourites"
HorizontalOptions="StartAndExpand"
VerticalOptions="Center" Padding="0">
<local:FavouritesPage Icon="favourites2.png" Title="Favourites"/>
</ContentPage>
<ContentPage Title="Info"
HorizontalOptions="StartAndExpand"
VerticalOptions="Center" Padding="0">
<local:MainPage Icon="statistics2.png" Title="Info"/>
</ContentPage>
</TabbedPage>
You can add NavigationPage.HasNavigationBar="False" to the TabbedPage tag in your XAML.
Then your code should look like this:
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:JacksCurrencyConverter;assembly=JacksCurrencyConverter"
x:Class="JacksCurrencyConverter.StartPage"
x:Name="Children"
HeightRequest="10" WidthRequest="10"
NavigationPage.HasNavigationBar="False">
...
Another way would be calling NavigationPage.SetHasNavigationBar(this, false); in the constructor or OnAppearing function of your Page.

Xamarin Forms: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

I am struggling with this issue. I created just a simple cross platform page here is XAML code:
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ForTesting.TestPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<ContentPage>
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0,40,0,0" Android="0,40,0,0" />
</ContentPage.Padding>
</ContentPage>
</CarouselPage>
And here is same cross platform page class:
public partial class TestPage: CarouselPage
{
public TestPage()
{
InitializeComponent();
new Label
{
Text = "heelow",
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
HorizontalOptions = LayoutOptions.Center
};
}
}
For testing I created simple label, but even without label it is doesn't work.
I am calling this page in my MainPage.xaml :
<?xml version="1.0" encoding="UTF-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ForTesting;assembly=ForTesting"
x:Class="ForTesting.MainPage"
MasterBehavior="Popover">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="CClick"
Text="C :"
Order="Primary">
</ToolbarItem>
</ContentPage.ToolbarItems>
<MasterDetailPage.Master>
<local:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:TestPage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
And on this line of class: ForTesting.MainPage.xaml.g.cs I am getting error when I am executing program:
public partial class MainPage : global::Xamarin.Forms.MasterDetailPage {
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private global::Xamarin.Forms.ToolbarItem CClick;
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private global::ForTesting.MasterPage masterPage;
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
--> this.LoadFromXaml(typeof(MainPage));
}
}
Error:
Unhandled Exception: System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation.
And I have another cross platform page which is same as TestPage.xaml , but it is working when I am executing.
To build upon #Wes answer, you can make the error message clearer by telling Visual Studio to automatically break at any exception:
Go to Debug > Windows > Exception Settings to open the Exception Settings window
Select the checkbox for the base exception System.Exception
Start debugging again.
In general, I've noticed that any syntax errors in XAML may show up as this exception.
You have mistake in your Carousel page
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ForTesting.TestPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<ContentPage>
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0,40,0,0" Android="0,40,0,0" />
</ContentPage.Padding>
</ContentPage>
</CarouselPage>
Carousel page should have only one child, and it should be a ContentPage, you won't be able to add both label and content page. Remove this line
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
If you want to have both label and content in a Carousel, I would suggest using something like CarouselView.
EDIT 1
I've create a sample Carousel project with latest Xamarin.Forms (2.2.0.31), I've tested it on iOS and Android and it works. You can use it as a starter to implement your version. I use this control in production app.

Categories