无法从'Xamarin.Forms.TextCell'转换为'Xamarin.Forms.View'

Nei*_*eil 1 c# xaml xamarin xamarin.forms

我正在尝试创建一个具有TextCell和SwitchCell元素的ViewCell.
这是我的代码 -

<ListView x:Name="AlarmList" HasUnevenRows="True" >
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Orientation="Horizontal">
                        <TextCell TextColor="#CCCCCC" Text="{Binding Name}" DetailColor="Red" Detail="{Binding Address}"></TextCell>
                        <SwitchCell />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

无法从'Xamarin.Forms.TextCell'转换为'Xamarin.Forms.View'

替代方案是使用这些

<Label ></Label>
<Switch ></Switch> 
Run Code Online (Sandbox Code Playgroud)

有没有其他方法来实现这样的东西.?
在此输入图像描述

Ger*_*uis 6

A StackLayout期望一个View对象,它基本上是任何UI元素,但不是Cells.您可以使用Xamarin Forms附带的预定义单元格,如果您想要推迟编写自己的布局.

你有一个好的开始,但你不能使用细胞.所以失去它们,并ViewCell按照你想要的方式布局.