c# - C# WPF 在 SelectedItem 上从另一个 DataGrid 绑定 DataGrid
问题描述
我有两个 DataGrid 元素。第一个加载了文章数据,第二个应该根据第一个 DataGrid 的 SelectedItem 显示更多数据。
第一个 DataGrid 与文章数据的绑定工作完美。
现在我有第二个,它应该根据第一个的选择显示更多数据。在 ViewModel.cs 我创建了以下内容:
public BindableCollection<ArticleDataModel> ArticleDataList {
get; set;
}
public BindableCollection<QuantityModel> WarehouseQuantityList {
get; set;
}
private ArticleDataModel currentSelection;
public ArticleDataModel CurrentSelection {
get {
return currentSelection;
}
set {
currentSelection = value;
NotifyOfPropertyChange(() => currentSelection);
this.LoadQuantity();
}
}
第一个 DatagridView 绑定到ArticleDataList,所有数据都正确显示。选择数据集时,我可以在调试器中看到调用了 LoadQuantity() 方法并且 WarehouseQuantityList 包含所有数据。
但是,数据没有显示给我,甚至没有显示记录行。
XAML 中的绑定如下所示:
<!-- Artikel ListView -->
<DataGrid Grid.Column="0" Grid.Row="0"
x:Name="ArticleDataList"
AutoGenerateColumns="False"
AlternatingRowBackground="#fafafa"
FontSize="14"
RowBackground="#eee"
HorizontalGridLinesBrush="#ddd"
VerticalGridLinesBrush="#ddd"
RowHeaderWidth="0"
SelectionMode="Single"
SelectionUnit="FullRow"
SelectedItem="{Binding CurrentSelection}">
和
<DataGrid x:Name="WarehouseQuantityList"
AutoGenerateColumns="False"
AlternatingRowBackground="#fafafa"
FontSize="14"
RowBackground="#eee"
HorizontalGridLinesBrush="#ddd"
VerticalGridLinesBrush="#ddd"
RowHeaderWidth="0"
SelectionMode="Single"
SelectionUnit="FullRow">
绑定两次都超过x:Name,项目绑定如下:
<DataGridTextColumn Header="Lagerplatz" Width="250" Binding="{Binding Path=Lagerplatz}"/>
两者的绑定在技术上是相同的,但我没有收到任何错误或异常。加载的数据是正确的,并且在 WarehouseQuantityList 中也可用。只有 DataGrid 看不到它们。所以我认为我犯了一个错误,只是不知道在哪里?
我总是乐于接受提示:-)
解决方案
推荐阅读
- jquery - 如何通过在请求中传递宽度参数来调整图像大小?
- c# - 自定义对象序列化与 PreserveReferencesHandling
- idris - 在 Idris 中使用间接相互递归数据类型进行整体检查
- firebase - Firebase 实时数据库 - 如果我使用密钥进行身份验证,auth.uid 的等价物是什么?
- python - Python 的 Anaconda 自动完成功能不起作用
- rest - 在 Grails 3 应用程序中使用 Spring Security Rest 对“refresh_token”请求的 403 响应
- delphi - 如何在整个 Delphi 应用程序中使用 ID
- java - 如何在 Spring Batch 中使用 MongoItemWriter 更新和插入文档?
- javascript - 删除 jQuery.trim() 忽略的文本区域中的空格
- kubernetes - 带有 kubernetes 入口和重定向的 traefik pathprefixstrip 不起作用