ComboBoxItem是一个ContentControl,我们可以使用任何控件作为内容
效果如下:
将图片和文字组合显示在ComboBoxItem上。
XAML:
<ComboBox x:Name="cbo2" SelectionChanged="cbo2_SelectionChanged">
<ComboBoxItem >
<StackPanel Orientation="Horizontal">
<Image Source="Images/W1.png" Height="30" Width="30"/>
<TextBlock Foreground="Red" VerticalAlignment="Center">W1</TextBlock>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Images/W2.png" Height="30" Width="30"/>
<TextBlock Foreground="Black" VerticalAlignment="Center">W2</TextBlock>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Images/W3.png" Height="30" Width="30"/>
<TextBlock Foreground="Green" VerticalAlignment="Center">W3</TextBlock>
</StackPanel>
</ComboBoxItem>
</ComboBox>
可以使用任何图片来测试代码,在项目中创建一个Images文件夹,放入测试的图片即可。