如何解决Xamarin CollectionView ItemsSource 绑定到 ContentView
我想将每个 CollectionView 项绑定到一个 ContentView。但我收到错误:
No property,BindableProperty,or event found for "Document",or mismatching type between value and property.
页面.xmal:
<CollectionView
ItemsSource="{Binding Documents}" >
<CollectionView.ItemTemplate>
<DataTemplate>
<controls:FoldersPageDocumentControl Document="{Binding .}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
页面视图模型:
private ObservableRangeCollection<Document> _Documents;
public ObservableRangeCollection<Document> Documents
{
get { return _Documents; }
set
{
_Documents = value;
OnPropertyChanged(nameof(Documents));
}
}
FoldersPageDocumentControl:
public Document Document
{
get { return (Document)GetValue(DocumentProperty); }
set { SetValue(DocumentProperty,value); }
}
public static readonly BindableProperty DocumentProperty = BindableProperty.Create(
returnType: typeof(Document),propertyName: nameof(Document),declaringType: typeof(FoldersPageDocumentControl),defaultValue: null );
为什么这不起作用? IntelliSense 显示 Binding .
是 Document 类型,但它不会接受它。
编辑:
public class Document
{
public bool DenyAtTextLogin { get; set; }
public bool Deleted { get; set; }
public bool Unread { get; set; }
public bool VerifiedSignatures { get; set; }
public bool Hidden { get; set; }
public int AccountID { get; set; }
public int ID { get; set; }
public int EncryptionType { get; set; }
public int FolderID { get; set; }
public int PageCount { get; set; }
public int RemoteID { get; set; }
public int Size { get; set; }
public int IsChildDocumentOfDocumentID { get; set; }
public int Type { get; set; }
public string Extension { get; set; }
public string Name { get; set; }
public DateTime CreationDate { get; set; }
public DateTime Level2StorageDate { get; set; }
public DateTime ProtectionDate { get; set; }
}
FoldersPageDocumentControl:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:eTApp.Controls"
x:DataType="controls:FoldersPageDocumentControl"
x:Class="eTApp.Controls.FoldersPageDocumentControl">
<ContentView.Content>
<Frame
HasShadow="False"
BorderColor="#ddd"
Padding="0,4,16,4"
CornerRadius="5">
<StackLayout>
<Label
Margin="16,4"
VerticalOptions="Center"
Grid.Column="0"
x:Name="labelName"
Text="{Binding Name}"
FontSize="18"
TextColor="{StaticResource TextPrimary}">
</Label>
</StackLayout>
</Frame>
</ContentView.Content>
</ContentView>
背后的代码:
[XamlCompilation(XamlCompilationoptions.Compile)]
public partial class FoldersPageDocumentControl : ContentView
{
public FoldersPageDocumentControl()
{
InitializeComponent();
}
public Document Document
{
get { return (Document)GetValue(DocumentProperty); }
set { SetValue(DocumentProperty,defaultValue: null );
public string Name { get { return Document?.Name; } }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。