public partial class Page14 : ContentPage
{
public Page14()
{
InitializeComponent();
this.BindingContext = new CustomerViewModel();
}
}
public class CustomerViewModel
{
public List<Customer> l_Customer { get; set; }
public CustomerViewModel()
{
l_Customer = new List<Customer>()
{
new Customer(){ fullname="A"},
new Customer(){ fullname="B"},
new Customer(){ fullname="C"},
};
}
}
public class Customer
{
public string fullname { get; set; }
}
<Picker Title="Select a customer"
ItemsSource="{Binding l_Customer}"
ItemDisplayBinding="{Binding fullname}" />
或在代码中
var picker = new Picker { Title = "Select a Customer" };
picker.SetBinding(Picker.ItemsSourceProperty, "l_Customer");
picker.ItemDisplayBinding = new Binding("fullname");
2条答案
按热度按时间wi3ka0sx1#
我用MVVM做了一个简单的例子供您参考。
XAML:
后面的代码:
xmd2e60i2#
在文档中有一个例子可以做到这一点
或在代码中