当我试图从我在项目控件中制作的一组动态组合框中获取选定的值时遇到了这个问题,为了更好地解释这里是我的 xaml 代码。
<ItemsControl Name="ItemsControlP"
                      Width="120"
                      Margin="5"
                      ItemsSource="{Binding ElementName=personWindow, Path=DataContext.City}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ComboBox Height="20"
                              DisplayMemberPath="Name"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding ElementName=personWindow, Path=DataContext.Person}"
                              SelectedIndex="0"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
城市和人员是 ObservableCollection 类型,因此对于每个城市,它显示一个组合框,每个组合框都有一个人员列表,然后我需要在每个组合框中捕获选定的值。有什么办法吗?