【发布时间】:2019-09-28 17:10:48
【问题描述】:
在这个MSDN tutorial 中,他们使用Model-View-ViewModel [MVVM] 将DataGrid 绑定到使用{x:Bind} markup extension 的客户列表,如下所示:
<controls:DataGrid x:Name="dataGrid1"
Height="600" Margin="12"
AutoGenerateColumns="True"
ItemsSource="{x:Bind MyViewModel.Customers}" />
他们有一个Customer 类如下:
//backing data source in MyViewModel
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)
});
}
}
问题:该教程中的MyViewModel 在哪里?
备注:我使用的是VS2019的最新6.3.1版
【问题讨论】: