gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:03 25 4
gpt4 key购买 nike

我正在尝试创建一个包含元素 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>

我得到的错误是:

cannot convert from 'Xamarin.Forms.TextCell' to 'Xamarin.Forms.View'

替代方法是使用这些

<Label ></Label>
<Switch ></Switch>

还有其他方法可以达到这样的效果吗?
enter image description here

最佳答案

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

您的开端不错,但您不能使用单元格。所以丢掉它们,然后按照您想要的方式布局 ViewCell

关于c# - 无法从 'Xamarin.Forms.TextCell' 转换为 'Xamarin.Forms.View',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44007132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com