gpt4 book ai didi

c# - 使用 MVVM 绑定(bind) : Property not found in Xamarin. 表单

转载 作者:行者123 更新时间:2023-12-05 08:25:25 25 4
gpt4 key购买 nike

XFC0045 绑定(bind):在“Page_Navigation.ViewModels.ThirdPageViewModel”上找不到属性“Tittle”。从该区域获取错误 - Page_Navigation\Views\ThirdPage.xaml

using Xamarin.Forms;

namespace Page_Navigation.ViewModels
{
public class ThirdPageViewModel : BindableObject
{
public ObservableCollection<Matches> MatchesList { get; set; }

public ThirdPageViewModel()
{
MatchesList = new ObservableCollection<Matches>();
MatchesList.Add(new Matches { Tittle = "Tittle 1", Description = "Description 1" });
MatchesList.Add(new Matches { Tittle = "Tittle 2", Description = "Description 2" });
MatchesList.Add(new Matches { Tittle = "Tittle 3", Description = "Description 3" });
MatchesList.Add(new Matches { Tittle = "Tittle 4", Description = "Description 4" });
}
}

public class Matches
{
public string Tittle { get; set; }
public string Description { get; set; }
}
}

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:VM="clr-namespace:Page_Navigation.ViewModels"
x:DataType="VM:ThirdPageViewModel"
x:Class="Page_Navigation.Views.ThirdPage"
NavigationPage.HasNavigationBar="True"
NavigationPage.HasBackButton="True"
Title="Third Page">

<ContentPage.BindingContext>
<VM:ThirdPageViewModel/>
</ContentPage.BindingContext>

<ContentPage.Content>
<ListView ItemsSource="{Binding MatchesList}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Label Text="{Binding Tittle}"/>
<Label Text="{Binding Description}"/>
</Grid>
</ViewCell>
</DataTemplate>

</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>

I don't know why this exception. I am using VS2019 and Xamarin.forms 4.8.0.1451

最佳答案

您必须删除 x:DataType 属性,因为它与编译绑定(bind)相关,并且您已经为 View 模型定义了 BindingContext。

在此处检查 XF 编译绑定(bind):Xamarin.Forms Compiled Bindings

关于c# - 使用 MVVM 绑定(bind) : Property not found in Xamarin. 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65791339/

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