我有两个组合框,一个用于组织和一个用于区域。选择组织时,我希望区域组合框使用相关区域自行更新。选择组织和区域后,我可以在文本框中键入一个网站并将其存储到数据库(ADD模式)。我已经完成了与此代码:如何在具有元素绑定的组合框中设置SelectedIndex?
<ComboBox x:Name="cbOrganisation"
Grid.Row="0"
Grid.Column="1"
ItemsSource="{Binding OrganisationEntries}"
SelectedItem="{Binding SelectedOrganisation, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOrganisationIndex}"
DisplayMemberPath="Description">
</ComboBox>
<ComboBox x:Name="cbRegions"
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding ElementName=cbOrganisation, Path=SelectedItem.Regions}"
SelectedItem="{Binding SelectedRegion, Mode=TwoWay}"
SelectedIndex="{Binding SelectedRegionIndex}"
DisplayMemberPath="Description" >
</ComboBox>
所以,我使用的元素元素绑定,具有第一个作为的ItemSource第二组合框。
现在,当我想编辑我的收藏中的网站时,出现了一个新问题。在编辑模式下,我希望预选和禁用两个下拉菜单(BusinessRule是我可以编辑网站名称,而不是与其连接的组织区域)。因此,通过在Organization组合框上设置SelectedIndex属性,我可以选择我的组织,但是在对区域组合框执行相同操作时,它会失败并显示对象引用错误。 任何线索我做错了什么?