WPF 组合框多重绑定对象的属性

Ias*_*son 1 .net c# data-binding wpf xaml

<ComboBox Style="{StaticResource Combobox}"  ItemContainerStyle="{StaticResource {x:Type ComboBoxItem}}"  DisplayMemberPath="Name" SelectedValuePath="Name"  HorizontalAlignment="Left"  VerticalAlignment="Top" Width="180" Height="25" Foreground="Black">
    <ComboBox.ItemsSource>
        <MultiBinding StringFormat="{}{0} {1}">
            <Binding Path="Name"/>
            <Binding Path="Identifier"/>
        </MultiBinding>
    </ComboBox.ItemsSource>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

我正在尝试绑定以显示应绑定的详细信息列表的ComboBoxItems名称和属性。我怎样才能做到这一点?IdentifierComboBox.ItemSource

基本上ItemSource应该绑定到一个对象列表(称为“详细信息”),并且每个对象都ComboBoxItem应该显示每个对象的Name+属性。Identifier

XAM*_*MAX 5

你应该用这个代替:

<ComboBox 
    ItemsSource="{Binding Details}"
    Style="{StaticResource Combobox}" 
    SelectedItem="{Binding SelectedItem}" 
    HorizontalAlignment="Left" 
    VerticalAlignment="Top" 
    Width="180" 
    Height="25" 
    Foreground="Black"
    >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} {1}">
                        <Binding Path="Name"/>
                        <Binding Path="Identifier"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)