关于使用MVVM的UWP DataGrid数据绑定的问题

问题描述 投票:0回答:1

第一次尝试使用MVVM绑定.NET应用程序中的数据。来自旧版.NET世界,我不太了解use of MVVM in a UWP app

我正在尝试将我的UWP应用程序中的MVVM控件与我的UWP(如下所示)绑定在一起,该DataGrid是在名为MVVM的项目的顶层创建的类。 问题:要填充客户数据,我应该在DataGrid控件的My_UWP_Project行的????中添加什么值?

备注:对于数据绑定,我使用Microsoft ItemsSource="{x:Bind ????}"建议的与{x:Bind} markup extension并置的新方法。

MainPage.xaml中的DataGrid控件]:

Binding class

Customer class

[ViewModel]:
<controls:DataGrid x:Name="dataGrid1" 
    Height="600" Margin="12"
    AutoGenerateColumns="True"
    ItemsSource="{x:Bind ????" />

第一次尝试使用MVVM绑定.NET应用程序中的数据。来自旧版.NET世界,我不太了解MVVM在UWP应用程序中的使用。我正在尝试绑定以下DataGrid ...

c# mvvm uwp
1个回答
0
投票

已经有一段时间我不开发UWP应用程序了,但是我记得您可以使用using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace My_UWP_Project { //backing data source public class Customer { public String FirstName { get; set; } public String LastName { get; set; } public String Address { get; set; } public Boolean IsNew { get; set; } public Customer(String firstName, String lastName, String address, Boolean isNew) { this.FirstName = firstName; this.LastName = lastName; this.Address = address; this.IsNew = isNew; } public static List<Customer> Customers() { return new List<Customer>(new Customer[4] { new Customer("A.", "Zero", "12 North Third Street, Apartment 45", false), new Customer("B.", "One", "34 West Fifth Street, Apartment 67", false), new Customer("C.", "Two", "56 East Seventh Street, Apartment 89", true), new Customer("D.", "Three", "78 South Ninth Street, Apartment 10", true) }); } } } 方法直接绑定viewmodel的属性或方法。

© www.soinside.com 2019 - 2024. All rights reserved.