WPF ComboBox ControlTemplate背景IsMouseOver

时间:2010-03-11 14:31:52

标签: wpf combobox triggers controltemplate ismouseover

我定义了以下样式(正在将文本更改为红色),但我似乎无法使Background属性起作用。谁能告诉我这有什么问题?

    <Style x:Key="CompanyComboItemContainerStyle" TargetType="ComboBoxItem">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="Red" />
                            <Setter Property="Background" Value="Black" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                    <StackPanel>
                        <TextBlock Text="{Binding CompanyName}" Grid.Column="0" />
                        <TextBlock Text="{Binding EIC, StringFormat=' ({0})'}" Grid.Column="1" FontFamily="Courier New" FontWeight="Bold" FontSize="12" />
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:3)

StackPanel上,您是否尝试过添加Background="{TemplateBinding Background}"