Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ComboBox项使用dataclass将信息导入textbox_C#_Wpf_Combobox - Fatal编程技术网

C# ComboBox项使用dataclass将信息导入textbox

C# ComboBox项使用dataclass将信息导入textbox,c#,wpf,combobox,C#,Wpf,Combobox,当我在组合框中选择一个项目时,我希望它将我的数据类中的信息显示在文本框中,例如,当我选择一个客户时,它会插入他的名字/姓氏和年龄 我有这个部分: DataClasses1DataContext db = new DataClasses1DataContext(); var customer = from employee in db.employees select employee; List<employee> myCustomer

当我在组合框中选择一个项目时,我希望它将我的数据类中的信息显示在文本框中,例如,当我选择一个客户时,它会插入他的名字/姓氏和年龄

我有这个部分:

        DataClasses1DataContext db = new DataClasses1DataContext();
        var customer = from employee in db.employees select employee;
        List<employee> myCustomers = customer.ToList();
        cmbKlant.ItemsSource = myCustomers;
        tbxFirstname.DisplayMemberPath = "firstnaam";
DataClasses1DataContext db=newdataclasses1datacontext();
var customer=来自数据库中的员工。员工选择员工;
List myCustomers=customer.ToList();
cmbKlant.ItemsSource=myCustomers;
tbxFirstname.DisplayMemberPath=“firstnaam”;

但最后一部分需要转换为字符串,而不是显示名字,而是实际数据,有人知道如何实现这一点吗?

首先,您应该使用带有MVVM模式的ViewModel。与绑定项的客户一起拥有一个属性Source,然后为SelectedCustomer拥有另一个属性,将组合框的selectedItem属性绑定到组合框,组合框将始终包含所选项,然后可以将文本框绑定到像SlectedCustomer.Firstname等