我有两个data grids
。一个将加载疾病疾病列表,一个将从艾瑞特表中加载一个刺激物列表。问题是我的database
中有相同的表名“Id”,“Name”,“Description”。如果(我认为)我绑定它们,它可能会变得模棱两可,因为它们是相同的形式。除了在database
中重命名整个表之外,有没有办法解决这个问题,比如在标记中指定要绑定的表?
这是我的疾病表:
<DataGrid.Columns>
<DataGridTextColumn x:Name="IdColumn" Binding="{Binding Id}" Header="Id" Visibility="Hidden"/>
<DataGridTextColumn x:Name="DiseaseNameColumn" Binding="{Binding Name}" Header="Name" MinWidth="250" />
<DataGridTextColumn x:Name="DiseaseDescriptionColumn" Binding="{Binding Description}" Header="Description" MinWidth="250" />
</DataGrid.Columns>
这是我的Irritants表:
<DataGrid.Columns>
<DataGridTextColumn x:Name="IdColumn" Binding="{Binding Id}" Header="Id" Visibility="Hidden"/>
<DataGridTextColumn x:Name="IrritantNameColumn" Binding="{Binding Name}" Header="Name" MinWidth="250" />
<DataGridTextColumn x:Name="IrrirtantDescriptionColumn" Binding="{Binding Description}" Header="Description" MinWidth="250" />
</DataGrid.Columns>
答案 0 :(得分:1)
您只需为2个表分配不同的名称:
疾病表:
<DataGrid x:Name="Diseases">
<DataGrid.Columns>
<DataGridTextColumn x:Name="IdColumn" Binding="{Binding Id}" Header="Id" Visibility="Hidden"/>
<DataGridTextColumn x:Name="IrritantNameColumn" Binding="{Binding Name}" Header="Name" MinWidth="250" />
<DataGridTextColumn x:Name="IrrirtantDescriptionColumn" Binding="{Binding Description}" Header="Description" MinWidth="250" />
</DataGrid.Columns>
</DataGrid>
刺激表
<DataGrid x:Name="Irritants">
<DataGrid.Columns>
<DataGridTextColumn x:Name="IdColumn" Binding="{Binding Id}" Header="Id" Visibility="Hidden"/>
<DataGridTextColumn x:Name="IrritantNameColumn" Binding="{Binding Name}" Header="Name" MinWidth="250" />
<DataGridTextColumn x:Name="IrrirtantDescriptionColumn" Binding="{Binding Description}" Header="Description" MinWidth="250" />
</DataGrid.Columns>
</DataGrid>
<
在* .cs后面的代码中,您可以在xaml网格中添加此代码以加载数据
Diseases.ItemsSource = ARRAY_OR_LIST_OR_COLLECTION_OF_DISEAS;
Irritants.ItemsSource = ARRAY_OR_LIST_OR_COLLECTION_OF_IRRITANTS;