我在我的datagrid分类类ComboBox和DisclosureNoteComboBox中有2个DataGridComboBoxColumn。第一个工作正常,我看到其中填充了数据。我想要的是,当在第一个项目中选择一个项目时,即CategoryComboBox,我希望第二个项目在第一个项目中显示所选项目的数据列表。[ClassificationComboBox]中选定的Item为[Classification]类型,并且有一个名为[ClassificationRecords]的列表,我想在DisclosureNoteComboBox中填充该列表。
这是我的XML的代码段。
<materialDesign:DataGridComboBoxColumn Header="Classification" IsEditable="False" x:Name="ClassificationComboBox"
ItemsSourceBinding="{Binding ElementName=TrialBalanceViewName, Path=Report.Classifications}"
DisplayMemberPath="Name"
SelectedValuePath="Id"
SelectedValueBinding="{Binding ClassificationRecord.ClassificationId}"
/>
<materialDesign:DataGridComboBoxColumn Header="Disclosure Note" IsEditable="False" x:Name="DisclosureNoteComboBox"
ItemsSourceBinding="{Binding ElementName=ClassificationComboBox, Path=SelectedValueBinding.ClassificationRecords}"
SelectedValuePath="DisclosureNote"
SelectedValueBinding="{Binding ClassificationRecord.DisclosureNote}"
/>
我怀疑我的问题是如何为第二个(尤其是路径)构造ItemsSourceBinding。我认为这是错误的,但是我不确定如何调用第一个的选定项并将其上的分类记录称为第二个的ItemSource
ItemsSourceBinding="{Binding ElementName=ClassificationComboBox, Path=SelectedValueBinding.ClassificationRecords}"
您无法解决这样的问题,因为数据网格列定义不包含所需的数据。它们是对DataGrid的指示,说明如何显示其项目,而不是项目本身的容器。
要解决这个问题,您需要绑定到数据模型,而不是列定义。
foo
。bar
具有由属性foo
填充的ItemsSource。