标签:rgba col ber combobox rop vat play string hang
1.ViewModel对象
public class DocumentAddUpdateViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<Department> AllDepartments { get; set; }
public Person Person{get;set;}
}
public class Person{
public String DepartmentId{get;set;}
}
在界面的类中
private DocumentAddUpdateViewModel viewModel = new DocumentAddUpdateViewModel ();
viewModel.AllDepartments = departmentService.GetAll();
最关键的是xaml中的绑定
<ComboBox
SelectedValue="{Binding Path=Person.DepartmentId}" /*1.这个用来绑定到对象的字段*/
ItemsSource="{Binding Path=AllDepartments}" /*2.用来绑定列表*/
DisplayMemberPath="ShowName" /*3.绑定时用来显示的列*/
SelectedValuePath="Id" /*4.这个是AllDepartments里的id,与3是一对*/
Width="250"
Height="30"
Style="{DynamicResource FormComboBoxStyle}" />
Wpf ComboBox 绑定关联对象列表 与实体对象中的相关ID列绑定的方式
标签:rgba col ber combobox rop vat play string hang
原文地址:https://www.cnblogs.com/hh8527/p/13829848.html