【问题标题】:Object of type 'System.String' cannot be converted to type 'Xamarin.Forms.View'“System.String”类型的对象无法转换为“Xamarin.Forms.View”类型
【发布时间】:2016-11-01 04:11:04
【问题描述】:

我有这个代码,但它得到了这个错误,我该如何解决这个问题?

“System.String”类型的对象无法转换为“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>

【问题讨论】:

  • 请出示完整的 XAML
  • Okey 已更新。
  • 您是否从 Page1.xaml.cs 上的 ContentPage 继承?
  • 请阅读我的更新
  • 您应该: 1) 在上面的代码中包含有问题的 cmets,然后发布/接受解释您如何删除 cmets 并解决问题的答案;或 2) 删除问题。正如所写的那样,没有得到答复,这对任何人都没有帮助。

标签: xaml xamarin xamarin.forms


【解决方案1】:

当我删除 StackLayout 中的纯文本时,这个问题已经解决。所以我把它改成了一个标签组件,并将纯文本放在了 text 属性中。

这是工作代码:

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

【讨论】:

  • 啊...在尝试找到解决方案 2 小时后,我注意到由于 StackLayout 中有一个 ` 字符,我收到了这个错误...谢谢!
【解决方案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>

先生,请尝试这样做,这样可以更改评论文本

问候

【讨论】:

    猜你喜欢
    • 2012-09-07
    • 2014-03-14
    • 2017-11-24
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多