Object of type 'System.String' cannot be converted to type 'Xamarin.Forms.View'

10,923

Solution 1

This problem has solved when I removed the plain text that is inside the StackLayout. So I have changed it to a label component and have put the plain text in the text property.

This is the working 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" x:Class="Project1.Page1">
  <ContentPage.Content>
    <StackLayout>
      <Label Text="Text"></Label>
      <Editor Text="I am an Editor" />
    </StackLayout>
  </ContentPage.Content>
</ContentPage>

Solution 2

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="Project1.Page1">
    <ContentPage.Content>
      <StackLayout>
        <Label Text="Text"></Label>
        <!--Some text here-->
        <Editor Text="I am an Editor" />
      </StackLayout>
    </ContentPage.Content>
  </ContentPage>

Try to do this sir, this way change the text for comment

Regards

Share:
10,923
Bengi Besçeli
Author by

Bengi Besçeli

Hi, I'm Bengi. I'm 42 years old and I'm a Web Developer since 1998.

Updated on June 13, 2022

Comments

  • Bengi Besçeli
    Bengi Besçeli about 2 years

    I have this code and it gets me this error, how can I fix this ?

    Object of type 'System.String' cannot be converted to type 'Xamarin.Forms.View'.

    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="Project1.Page1">
        <ContentPage.Content>
          <StackLayout>
            <Label Text="Text"></Label>
            Some text here
            <Editor Text="I am an Editor" />
          </StackLayout>
        </ContentPage.Content>
      </ContentPage>
    
  • Dr TJ
    Dr TJ almost 8 years
    Ah... after 2 hours trying to find a solution, I noticed that because of one ` character inside the StackLayout I was receiving this error... Thank you!