讓ComboBoxItem前面帶一張圖

  • 955
  • 0
  • 2013-07-01

摘要:讓每個ComboBoxItem前面帶一張圖

讓每個ComboBoxItem前面帶一張圖

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="ComboBoxItem">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <Border Name="Border"
                                Padding="2"
                                SnapsToDevicePixels="true">
                            <DockPanel>
                                <Image Source="E:\Temp\1.JPG" Width="16" Height="16"/>
                                <ContentPresenter />
                            </DockPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ComboBox HorizontalAlignment="Left" Margin="63,91,0,0" VerticalAlignment="Top" Width="120">
            <ComboBoxItem Content="a"/>
            <ComboBoxItem Content="b"/>
            <ComboBoxItem Content="c"/>
        </ComboBox>

    </Grid>
</Window>