无法将类型为"System.String"的对象转换为类型为"Xamarin.Forms.View"的对象 [英] Object of type 'System.String' cannot be converted to type 'Xamarin.Forms.View'

查看:107
本文介绍了无法将类型为"System.String"的对象转换为类型为"Xamarin.Forms.View"的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,它使我得到此错误,我该如何解决呢?

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

类型为'System.String'的对象不能转换为类型为'Xamarin.Forms.View'.

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>

推荐答案

当我删除StackLayout中的纯文本时,此问题已解决.因此,我将其更改为标签组件,并将纯文本放置在text属性中.

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.

这是工作代码:

<?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>

这篇关于无法将类型为"System.String"的对象转换为类型为"Xamarin.Forms.View"的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆