我有这个代码,它让我犯了这个错误,我该怎么办?
类型的对象' 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>
答案 0 :(得分:21)
当我删除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>
答案 1 :(得分: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>
尝试这样做先生,这样就可以更改评论文本
此致