【问题标题】:WPF DATAGRID - How to binding two tables fields in xamlWPF DATAGRID - 如何在 xaml 中绑定两个表字段
【发布时间】:2009-08-23 13:46:20
【问题描述】:

请帮忙。

我有两个关系表,即 Employee 和 EmployeePosition。我正在尝试将两个表绑定到 xmal 文件上的一个数据网格中不使用 LINQ 将这两个表从后面的 c# 代码中加入一个集合。我该怎么做? 下面的示例代码和表格

员工 员工ID 名 姓 职位ID

员工职位 职位编号 标题

我的例外结果是:

EmployeeID   FirstName   LastName  Title

Xaml 文件

<DataGrid x:Name="DataGrid">
  <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/>
  <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>            
  <DataGridTextColumn Header="Title" Binding="{Binding Title}"/>
</DataGrid>

C# 代码

var employee = from e in _db.Employees
               select e;
this.DataGrid.ItemsSource = employee;

请帮忙 帕特里克

【问题讨论】:

  • 您使用的是哪个持久层(LINQ-to-SQL、实体框架等)?

标签: c# .net wpf datagrid


【解决方案1】:

你在使用 Linq-2-SQL 吗? Linq-2-实体?

无论如何,您应该在Employee 类型中有一个导航属性EmployeePosition。 确保当它急切加载时(很难告诉你,因为我不知道你使用什么 Linq),EmployeePropertyChanged 事件(应该实现INotifyPropertyChanged)使用该属性名称引发.

然后你可以简单地在xaml中绑定它:Binding="{Binding EmployeePosition.Position}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多