我有一张带有外键的表。我想将数据显示为描述,而不是相关表的 Id。从实体服务中,我已经.Include
对数据模型进行了声明以使其返回。这是我尝试过的,电台出现在单元格中,但组合框中没有任何内容:
<sdk:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" CanUserSort="False" Width="Auto" Header="Station">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Station.Description}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Station}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
<OperationContract()>
Public Function LoadPersonnel(clientId As Integer) As List(Of Personnel)
Dim result As List(Of Personnel)
Try
result = db.Personnels.Include("Station").Where(Function(o) o.ClientId = clientId).ToList
Catch
result = Nothing
End Try
Return result
End Function
也试过:
<ComboBox ItemsSource="{Binding}" DisplayMemberPath="{Binding Station.Description}" SelectedItem="{Binding Station.Description}" SelectedValue="{Binding Station.StationId}" />