c# - 使用 MVVM 绑定(bind) : Property not found in Xama

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/

相关文章:

javascript - 句号、单词和冒号的正则表达式

arrays - 检查列表和数组是否相等 F#

python - 如何从时间序列数据中选择前 n 列而不是在 pandas 中使用 nlargest

python - 如何连接来自 3 个小整数的字节以生成由 Python 中的这些字节表示的更大数字

r - 如何在 R 中的数据框中重新编码数据

javascript - 对象可能是 'null' : TypeScript, React useR

list - 在 Elixir 中使用类型规范中的原子列表

reactjs - 有没有 Ionicons : Icon props?

java - Java 是否根据结果假定类型?

react-native - react native : Refresh Controll not