Xamarin CollectionView项目资源绑定到ContentView
我想将每个CollectionView项绑定到ContentView。但我得到了一个错误:Xamarin CollectionView项目资源绑定到ContentView,xamarin,binding,Xamarin,Binding,我想将每个CollectionView项绑定到ContentView。但我得到了一个错误: 找不到“文档”的属性、BindableProperty或事件,或者值和属性之间的类型不匹配。 Page.xmal: <CollectionView ItemsSource="{Binding Documents}" > <CollectionView.ItemTemplate> <Data
找不到“文档”的属性、BindableProperty或事件,或者值和属性之间的类型不匹配。
Page.xmal:
<CollectionView
ItemsSource="{Binding Documents}" >
<CollectionView.ItemTemplate>
<DataTemplate>
<controls:FoldersPageDocumentControl Document="{Binding .}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
为什么这不起作用?IntelliSense向我展示了绑定。
属于Document类型,但它不会接受它
编辑: 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 );
<?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,0,0,4"
VerticalOptions="Center"
Grid.Column="0"
x:Name="labelName"
Text="{Binding Name}"
FontSize="18"
TextColor="{StaticResource TextPrimary}">
</Label>
</StackLayout>
</Frame>
</ContentView.Content>
</ContentView>
什么是文件?请发布FoldersPageDocumentControl的完整代码?
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; }
}
<?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,0,0,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, value); }
}
public static readonly BindableProperty DocumentProperty = BindableProperty.Create(
returnType: typeof(Document),
propertyName: nameof(Document),
declaringType: typeof(FoldersPageDocumentControl),
defaultValue: null );
public string Name { get { return Document?.Name; } }
}