-1

このMSDN チュートリアルでは、Model-View-ViewModel [MVVM]を使用して、次のように{x:Bind} マークアップ拡張機能を使用して DataGrid を顧客のリストにバインドしています。

<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そのチュートリアルのどこにあるのですか?

備考:最新バージョン6.3.1を使用していますVS2019

4

2 に答える 2

0

そのチュートリアルの MyViewModel はどこにありますか?

MyViewModelを返すプロパティMainPage.xaml.csを持つクラスのインスタンスを返す のプロパティであると想定されています。CustomersIEnumerable<Customer>

マークアップ拡張機能が DataContext または INotifyPropertyChanged を使用{x:Bind}していないようです

確かに a は使用しませんDataContextが、ソース プロパティから値を取得し、マークアップで指定されたターゲット プロパティに設定するコードを生成します。これは、実行時にリフレクションを使用してバインディング パスを解決するよりも高速です。

INotifyPropertyChangedただし、プロパティの変更の通知は引き続き適用され{x:Bind}ます。

于 2019-10-01T11:37:15.653 に答える