Xaml Xamarin自定义ViewCell
在创建自定义嵌套视图时,我遇到了一个问题。 我正在尝试使用来自不同页面的自定义视图(ViewCell)。 我就是这样用的 如果我对Xaml和codebehind使用View,它不会产生任何错误, 但它不会显示任何东西 如果我尝试将ViewCell用于xaml及其代码隐藏,则会出现一些错误。 我就是这样用的 在主页xaml中Xaml Xamarin自定义ViewCell,xaml,xamarin,data-binding,xamarin.forms,Xaml,Xamarin,Data Binding,Xamarin.forms,在创建自定义嵌套视图时,我遇到了一个问题。 我正在尝试使用来自不同页面的自定义视图(ViewCell)。 我就是这样用的 如果我对Xaml和codebehind使用View,它不会产生任何错误, 但它不会显示任何东西 如果我尝试将ViewCell用于xaml及其代码隐藏,则会出现一些错误。 我就是这样用的 在主页xaml中 <local:UploaderCell Uploader="{Binding post.uploader}"/> 我从主页上得到这个错误 object of
<local:UploaderCell Uploader="{Binding post.uploader}"/>
我从主页上得到这个错误
object of type Project.UploaderCell cannot be converted to type 'xamarin.forms.view'
我做错了什么?
我怎么可能做到这一点呢?单元格只能在ListView或TableView中使用。听起来你想直接在页面中使用它。如果这是您需要的,请使用ContentView。实际上,我正在列表视图内部的viewcell下使用它。。。在这种情况下,我应该使用什么?您需要显示主页xaml中的更多上下文。是的,您正在尝试将自定义单元格与另一个ViewCell中的其他元素组合。这不是细胞的工作原理。将你的UploaderCell改为从ContentView继承。我知道这已经很晚了,但我现在正在亲自研究这个问题,无意中发现了这个问题。如果你解决了这个问题,怎么解决?如果没有,是否只需将
..
更改为..
就可以了?在我看来,您似乎正在将自定义的ViewCell
放置在ViewCell
中。单元格只能在ListView或TableView中使用。听起来你想直接在页面中使用它。如果这是您需要的,请使用ContentView。实际上,我正在列表视图内部的viewcell下使用它。。。在这种情况下,我应该使用什么?您需要显示主页xaml中的更多上下文。是的,您正在尝试将自定义单元格与另一个ViewCell中的其他元素组合。这不是细胞的工作原理。将你的UploaderCell改为从ContentView继承。我知道这已经很晚了,但我现在正在亲自研究这个问题,无意中发现了这个问题。如果你解决了这个问题,怎么解决?如果没有,是否只需将..
更改为..
就可以了?在我看来,您似乎正在将自定义的ViewCell
放置在ViewCell
中。
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell
xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="EodiRoad.UploaderCell">
<StackLayout Orientation="Horizontal" Padding="5">
<Button Clicked="Handle_Clicked" Image="{Binding Uploader.userProfile.userThumbnail}" BorderRadius="5" HeightRequest="50" WidthRequest="50"/>
<ic:CircleImage
x:Name="userProfileImage"
HeightRequest="50"
WidthRequest="50"
Aspect="AspectFill"
Source="{Binding Uploader.userProfile.userThumbnail}"
/>
<Label Text="{Binding Uploader.username}"/>
</StackLayout>
</ViewCell>
public partial class UploaderCell : ViewCell
{
public static readonly BindableProperty UploaderProperty =
BindableProperty.Create(
propertyName: "Uploader",
returnType: typeof(UserModel),
declaringType: typeof(UploaderCell)
);
public UserModel Uploader
{
get
{ return GetValue(UploaderProperty) as UserModel; }
set
{ SetValue(UploaderProperty, value); }
}
public UploaderCell()
{
InitializeComponent();
BindingContext = this;
}
}
object of type Project.UploaderCell cannot be converted to type 'xamarin.forms.view'