1 传统的 disPlayMemberPath 的方式
<ComboBox x:Name="SupplierCodeComboBox" Grid.Column="1" DisplayMemberPath="SupplierName" HorizontalAlignment="Left" ItemsSource="{Binding obsOfSupplier}" Height="Auto"
Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="120" SelectedValuePath="SupplierCode" SelectedValue="{Binding CurrentItem.SupplierCode}"
>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
2 ItemTemplate 的显示方式,这样可以做到多控件,多方式,较为灵活,多变,强大
<ComboBox Grid.Column="1" HorizontalAlignment="Left" Height="Auto" ItemsSource="{ Binding obsOfSupplier}" SelectedValue="{Binding CurrentItem.SupplierCode}"
Margin="301,7,-478,3" Grid.Row="0" VerticalAlignment="Center" Width="400" IsTextSearchEnabled="True" SelectedValuePath="SupplierCode" >
<ComboBox.ItemTemplate >
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding SupplierCode}" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding SupplierName}" Grid.Column="1"></TextBlock>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
总结: 三个必须属性 ItemSource :指定数据源; selectedValuePath 指定选择后的值 selectedValue 选择后的值用于哪一个I属性保存,绑定,或者用哪一个属性进行初始化
区别 : 1 displayMemberPath 指定显示的属性 2 ItemTemplate 指定显示的属性