【发布时间】:2013-12-18 08:20:11
【问题描述】:
我向Combobox 提出了类似的问题,并得到了很好的答案。现在,如果可能的话,我想将DataGridTextColumn 绑定到Foreign Key。否则我可以将DataGridTemplateColumn 绑定到Foreign Key。
为了证明我的问题,让我们看一个例子:
假设我有两张桌子:
客户
CustomerID
Name
Gender //ForeignKey
性别
GenderID
Value
我正在使用entity framework 自动生成我的Models。
现在我尝试如下绑定DataGridTemplateColumn:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding DataContext.Customers, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
SelectedItem="{Binding SelectedPatient}" RowDetailsVisibilityMode="VisibleWhenSelected"
IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Patient Name" Width="25*" />
<!--<DataGridTextColumn Binding="{Binding Gender}" Header="Gender" Width="10*" />-->
<DataGridTemplateColumn Header="Gender" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ???}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ???}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid>
但我不知道正确的绑定。
希望有人帮忙。
【问题讨论】: