MultiSelect for UWP
オブジェクトコレクションへのMultiSelectの連結
データ連結 > オブジェクトコレクションへのMultiSelectの連結

You can bind MultiSelect to a list of complex data objects which can have multiple properties. To bind the control to a list of data objects, follow these steps:

  1. Create a class named Customer using the following code.
    C#
    コードのコピー
    public class Customer
        {
            string name;
            string customerID;
            string mobile;
            string email;
            public Customer(string _name, string _custId, string _mobile, string _email)
            {
                this.name = _name;
                this.customerID = _custId;
                this.mobile = _mobile;
                this.email = _email;
            }
    
            public string Name
            {
                get
                {
                    return name;
                }
            }
            public string CustomerID
            {
                get
                {
                    return customerID;
                }
            }
            public string Mobile
            {
                get
                {
                    return mobile;
                }
            }
            public string Email
            {
                get
                {
                    return email;
                }
            }
        }
    
  2. Add objects of Customer class to ObservableCollection and set C1MultiSelect’s ItemsSource and DisplayMemberPath properties in the class constructor.
    C#
    コードのコピー
    ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
    customers.Add(new Customer("John", "C001", "8888832141", "john@gmail.com"));
    customers.Add(new Customer("Alex", "C002", "8888832142", "@gmail.com"));
    customers.Add(new Customer("Shawn", "C003", "8888832143", "shawn@gmail.com"));
    customers.Add(new Customer("Sam", "C004", "8888832144", "sam@gmail.com"));
    customers.Add(new Customer("Neo", "C005", "8888832145", "neo@gmail.com"));
    customers.Add(new Customer("Paul", "C006", "8888832146", "paul@gmail.com"));
    this.mselect.ItemsSource = customers;
    this.mselect.DisplayMemberPath = "Name";