Reputation: 85
I've just start new Xamarin.Forms project and I don't know what I'm doing wrong. In my App.cs file I'm trying to set my TestPage(I've created TestPage by Add->New Item-> BlankPage) as Main Page but i'm geting this error "Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'Paternity_Test.TestPage' to 'Xamarin.Forms.Page'"
My TesPage.xaml.cs
namespace Paternity_Test
{
public partial class TestPage : Xamarin.Forms.Page
{
public TestPage()
{
this.InitializeComponent();
}
}
}
And My App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace Paternity_Test
{
public class App : Application
{
public App ()
{
MainPage = new TestPage(); //here Im geting this error
}
protected override void OnStart ()
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}
What I'm doing wrong?
Upvotes: 4
Views: 5912
Reputation: 1217
Device.OnPlatform has been deprecated and the suggestion is to use switch(Device.RuntimePlatform)
Below is an example using the switch:
switch(Device.RuntimePlatform)
{
case Device.iOS:
Padding = new Thickness(0, 20, 0, 0);
break;
case Device.Android:
Padding = new Thickness(10, 20, 0, 0);
break;
case Device.WinPhone:
Padding = new Thickness(30, 20, 0, 0);
break;
}
Upvotes: 0
Reputation: 74184
<Page x:Class="Paternity_Test.TestPage" xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"; xmlns:x="schemas.microsoft.com/winfx/2006/xaml"; xmlns:local="using:Paternity_Test" xmlns:d="schemas.microsoft.com/expression/blend/2008"; xmlns:mc="schemas.openxmlformats.org/markup-compatibility/2006"; mc:Ignorable="d">
You can not use those Microsoft XAML namespaces, they need to be Xamarin/ WinFx based:
FYI: You can not currently use Blend
to create these XAML files
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TableHeaderBug.MyView">
<ContentView.Content>
</ContentView.Content>
</ContentView>
<?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="TableHeaderBug.MyPage99">
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
Part 1. Getting Started with XAML
The first XML namespace declaration means that tags defined within the XAML file with no prefix refer to classes in Xamarin.Forms, for example ContentPage. The second namespace declaration defines a prefix of x. This is used for several elements and attributes that are intrinsic to XAML itself and which (in theory) are supported by all implementations of XAML. However, these elements and attributes are slightly different depending on the year embedded in the URI. Xamarin.Forms supports the 2009 XAML specification, but not all of it.
Upvotes: 2