首页 > 解决方案 > 如何在组合框中添加一些图像作为下拉菜单?

问题描述

我有一些快速图标,使我的软件易于使用。但现在根据我的客户要求,我需要将这些图标设置为下拉菜单。有谁知道如何做到这一点?

我已经尝试过正常的组合框代码 XAML。但无法添加图像。在代码隐藏或 DbModels 中有没有更好的方法?

<ComboBox HorizontalAlignment="Center" Grid.Row="2"
Grid.Column="5"  x:Name="DropDownSearchMode" Style="{StaticResource 
ComboBoxStyle}">

    <ComboBoxItem Content="X"/>
    <ComboBoxItem Content="Y"/>
    <ComboBoxItem Content="Z"/>

</ComboBox>

我想要一些图标来显示下拉菜单,而不是 X、Y 和 Z。谁能帮我?

标签: c#imagexamlcombobox

解决方案


像这样:

<StackPanel Margin="10">
    <ComboBox>
        <ComboBoxItem>
            <StackPanel Orientation="Horizontal">
                <Image Source="red.png" />
                <TextBlock Foreground="Red">Red</TextBlock>
            </StackPanel>
        </ComboBoxItem>
        <ComboBoxItem>
            <StackPanel Orientation="Horizontal">
                <Image Source="green.png" />
                <TextBlock Foreground="Green">Green</TextBlock>
            </StackPanel>
        </ComboBoxItem>
        <ComboBoxItem>
            <StackPanel Orientation="Horizontal">
                <Image Source="blue.png" />
                <TextBlock Foreground="Blue">Blue</TextBlock>
            </StackPanel>
        </ComboBoxItem>
    </ComboBox>
</StackPanel>

推荐阅读