如何在鼠标悬停样式ComboBox背景? [英] How to style ComboBox Background on Mouse Hover?

查看:195
本文介绍了如何在鼠标悬停样式ComboBox背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含ComboBox的圆角边框

 < Border CornerRadius =10BorderBrush ...& 
< ComboBox Background ={x:Null}>
< ComboBoxItem ...>
< ComboBoxItem ...>
< / ComboBox>
< / Border>

当我的鼠标不悬停在Combobox的顶部时,它看起来漂亮和透明。像这样:



当鼠标悬停在它上面时,它会产生像Button一样的旧背景,如下:





我想要ComboBox具有透明背景,即使当鼠标在顶部。我尝试了各种方式,包括编写MouseEnter,MouseLeave,MouseMove将背景设置为null,但没有成功。

  private void ComboBox_MouseEnter (object sender,RoutedEventArgs e)
{
comboBox1.Background = null;
}

然后尝试设置样式:

 < Window.Resources> 
< Style TargetType ={x:Type ComboBox}x:Key =HoverBox>
< Style.Triggers>
< Trigger Property =IsMouseOverValue =True>
< Setter Property =BackgroundValue =Pink/>
< / Trigger>
< / Style.Triggers>
< / Style>
< /Window.Resources>

然后我尝试修改控制模板:

 < ControlTemplate TargetType ={x:Type ComboBox}x:Key = MouseHover> 
< ControlTemplate.Triggers>
< Trigger Property =IsMouseOverValue =True>
< Setter Property =BackgroundValue =Red/>
< Setter Property =ForegroundValue =Green/>
< / Trigger>
< /ControlTemplate.Triggers>
< / ControlTemplate>

最糟糕的是,在我修改Control模板后,ComboBox消失,如下所示:



>



我已经做了一切可能,但是我仍然得到这个丑的按钮背景在我的ComboBox每当我的鼠标悬停在它。



任何人都知道这里发生了什么问题?

解决方案

帖子要求相同



无法在鼠标悬停上对WPF ComboBox进行样式



如何在鼠标悬停期间更改ComboBox的背景属性



EDIT



使用这样。下面是组合框的默认控制模板。注意您的需求的注释代码行

 < Window.Resources> 
<! - 填充画笔 - >

< LinearGradientBrush x:Key =NormalBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#FFFOffset =0.0/>
< GradientStop Color =#CCCOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =Horizo​​ntalNormalBrushStartPoint =0,0EndPoint =1,0>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#FFFOffset =0.0/>
< GradientStop Color =#CCCOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =LightBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#FFFOffset =0.0/>
< GradientStop Color =#EEEOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =Horizo​​ntalLightBrushStartPoint =0,0EndPoint =1,0>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#FFFOffset =0.0/>
< GradientStop Colour =#EEEOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =DarkBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#FFFOffset =0.0/>
< GradientStop Color =#AAAOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =PressedBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#BBBOffset =0.0/>
< GradientStop Color =#EEEOffset =0.1/>
< GradientStop Color =#EEEOffset =0.9/>
< GradientStop Color =#FFFOffset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< SolidColorBrush x:Key =DisabledForegroundBrushColor =#888/>

< SolidColorBrush x:Key =DisabledBackgroundBrushColor =#EEE/>

< SolidColorBrush x:Key =WindowBackgroundBrushColor =#FFF/>

< SolidColorBrush x:Key =SelectedBackgroundBrushColor =#DDD/>

<! - Border Brush - >

< LinearGradientBrush x:Key =NormalBorderBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#CCCOffset =0.0/>
< GradientStop Color =#444Offset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =Horizo​​ntalNormalBorderBrushStartPoint =0,0EndPoint =1,0>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#CCCOffset =0.0/>
< GradientStop Color =#444Offset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =DefaultedBorderBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#777Offset =0.0/>
< GradientStop Color =#000Offset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< LinearGradientBrush x:Key =PressedBorderBrushStartPoint =0,0EndPoint =0,1>
< GradientBrush.GradientStops>
< GradientStopCollection>
< GradientStop Color =#444Offset =0.0/>
< GradientStop Color =#888Offset =1.0/>
< / GradientStopCollection>
< /GradientBrush.GradientStops>
< / LinearGradientBrush>

< SolidColorBrush x:Key =DisabledBorderBrushColor =#AAA/>

< SolidColorBrush x:Key =SolidBorderBrushColor =#888/>

< SolidColorBrush x:Key =LightBorderBrushColor =#AAA/>

<! - 杂项画笔 - >
< SolidColorBrush x:Key =GlyphBrushColor =#444/>

< SolidColorBrush x:Key =LightColorBrushColor =#DDD/>

< ControlTemplate x:Key =ComboBoxToggleButtonTargetType =ToggleButton>
< Grid>
< Grid.ColumnDefinitions>
< ColumnDefinition />
< ColumnDefinition Width =20/>
< /Grid.ColumnDefinitions>
< Border
x:Name =Border
Grid.ColumnSpan =2
CornerRadius =2
Background ={StaticResource NormalBrush}
BorderBrush ={StaticResource NormalBorderBrush}
BorderThickness =1/>
< Border
Grid.Column =0
CornerRadius =2,0,0,2
Margin =1
Background ={ staticbourceBrush}
BorderBrush ={StaticResource NormalBorderBrush}
BorderThickness =0,0,1,0/>
< Path
x:Name =Arrow
Grid.Column =1
Fill ={StaticResource GlyphBrush}
Horizo​​ntalAlignment =Center
VerticalAlignment =Center
Data =M 0 0 L 4 4 L 8 0 Z/>
< / Grid>
< ControlTemplate.Triggers>
<! - < Trigger Property =ToggleButton.IsMouseOverValue =true>
< Setter TargetName =BorderProperty =BackgroundValue ={StaticResource DarkBrush}/>
< / Trigger> - >
< Trigger Property =ToggleButton.IsCheckedValue =true>
< Setter TargetName =BorderProperty =BackgroundValue ={StaticResource PressedBrush}/>
< / Trigger>
< Trigger Property =IsEnabledValue =False>
< Setter TargetName =BorderProperty =BackgroundValue ={StaticResource DisabledBackgroundBrush}/>
< Setter TargetName =BorderProperty =BorderBrushValue ={StaticResource DisabledBorderBrush}/>
< Setter Property =ForegroundValue ={StaticResource DisabledForegroundBrush}/>
< Setter TargetName =ArrowProperty =FillValue ={StaticResource DisabledForegroundBrush}/>
< / Trigger>
< /ControlTemplate.Triggers>
< / ControlTemplate>

< ControlTemplate x:Key =ComboBoxTextBoxTargetType =TextBox>
< Border x:Name =PART_ContentHostFocusable =FalseBackground ={TemplateBinding Background}/>
< / ControlTemplate>

< Style x:Key ={x:Type ComboBox}TargetType =ComboBox>
< Setter Property =SnapsToDevicePixelsValue =true/>
< Setter Property =OverridesDefaultStyleValue =true/>
< Setter Property =ScrollViewer.Horizo​​ntalScrollBarVisibilityValue =Auto/>
< Setter Property =ScrollViewer.VerticalScrollBarVisibilityValue =Auto/>
< Setter Property =ScrollViewer.CanContentScrollValue =true/>
< Setter Property =MinWidthValue =120/>
< Setter Property =MinHeightValue =20/>
< Setter Property =Template>
< Setter.Value>
< ControlTemplate TargetType =ComboBox>
< Grid>
< ToggleButton
Name =ToggleButton
Template ={StaticResource ComboBoxToggleButton}
Grid.Column =2
Focusable =false
IsChecked ={Binding Path = IsDropDownOpen,Mode = TwoWay,RelativeSource = {RelativeSource TemplatedParent}}
ClickMode =Press>
< / ToggleButton>
< ContentPresenter
Name =ContentSite
IsHitTestVisible =False
Content ={TemplateBinding SelectionBoxItem}
ContentTemplate ={TemplateBinding SelectionBoxItemTemplate}
ContentTemplateSelector ={TemplateBinding ItemTemplateSelector}
Margin =3,3,23,3
VerticalAlignment =Center
Horizo​​ntalAlignment =Left/&
< TextBox x:Name =PART_EditableTextBox
Style ={x:Null}
Template ={StaticResource ComboBoxTextBox}
Horizo​​ntalAlignment =Left
VerticalAlignment =Center
Margin =3,3,23,3
Focusable =True
Background =Transparent
Visibility =Hidden
IsReadOnly ={TemplateBinding IsReadOnly}/>
< Popup
Name =Popup
Placement =Bottom
IsOpen ={TemplateBinding IsDropDownOpen}
AllowTransparency =True
Focusable =False
PopupAnimation =Slide>
< Grid
Name =DropDown
SnapsToDevicePixels =True
MinWidth ={TemplateBinding ActualWidth}
MaxHeight ={TemplateBinding MaxDropDownHeight}> ;
< Border
x:Name =DropDownBorder
Background ={StaticResource WindowBackgroundBrush}
BorderThickness =1
BorderBrush ={StaticResource SolidBorderBrush} />
< ScrollViewer Margin =4,6,4,6SnapsToDevicePixels =True>
< StackPanel IsItemsHost =TrueKeyboardNavigation.DirectionalNavigation =Contained/>
< / ScrollViewer>
< / Grid>
< / Popup>
< / Grid>
< ControlTemplate.Triggers>
< Trigger Property =HasItemsValue =false>
< Setter TargetName =DropDownBorderProperty =MinHeightValue =95/>
< / Trigger>
< Trigger Property =IsEnabledValue =false>
< Setter Property =ForegroundValue ={StaticResource DisabledForegroundBrush}/>
< / Trigger>
< Trigger Property =IsGroupingValue =true>
< Setter Property =ScrollViewer.CanContentScrollValue =false/>
< / Trigger>
< Trigger SourceName =PopupProperty =Popup.AllowsTransparencyValue =true>
< Setter TargetName =DropDownBorderProperty =CornerRadiusValue =4/>
< Setter TargetName =DropDownBorderProperty =MarginValue =0,2,0,0/>
< / Trigger>
< Trigger Property =IsEditable
Value =true>
< Setter Property =IsTabStopValue =false/>
< Setter TargetName =PART_EditableTextBoxProperty =VisibilityValue =Visible/>
< Setter TargetName =ContentSiteProperty =VisibilityValue =Hidden/>
< / Trigger>
< /ControlTemplate.Triggers>
< / ControlTemplate>
< /Setter.Value>
< / Setter>
< Style.Triggers>
< / Style.Triggers>
< / Style>

< /Window.Resources>


I have a Rounded Border that contains a ComboBox

<Border CornerRadius="10"  BorderBrush...>
   <ComboBox Background="{x:Null}">
      <ComboBoxItem ...>
      <ComboBoxItem ...>
   </ComboBox>
</Border>

When my mouse is not hovering on top of the Combobox, it looks nice and transparent. Like this:

When the mouse hovers on it, it then produce the old, Button-like, background, like this:

I would like the ComboBox to have with a transparent background even when mouse is hoving on top. I tried various ways including writing MouseEnter, MouseLeave, MouseMove to set the background to null, but with no success.

private void ComboBox_MouseEnter(object sender, RoutedEventArgs e)
{
   comboBox1.Background = null;
}

I then try to set the Styling:

<Window.Resources>
    <Style TargetType="{x:Type ComboBox}" x:Key="HoverBox">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="Pink" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

that didn't work either. Then I tried modifying the control template:

<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="MouseHover">
    <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Red" />
            <Setter Property="Foreground" Value="Green" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

Worst, after I modify the Control template the ComboBox disappear, like follow:

I have done everything possible, but I am still getting that ugly button-background on my ComboBox whenever my mouse is hover on it.

Anyone knows what's going wrong here?

解决方案

Check your Previous Posts asking the same

Unable to style WPF ComboBox on Mouse Hover

How to change ComboBox's Background Property during Mouse Hover

EDIT

Use like this. Below is the default controltemplate of the combobox. Note the commented line of code for your requirement

   <Window.Resources>
        <!-- Fill Brushes -->

        <LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#CCC" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="HorizontalNormalBrush" StartPoint="0,0" EndPoint="1,0">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#CCC" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="LightBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#EEE" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="HorizontalLightBrush" StartPoint="0,0" EndPoint="1,0">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#EEE" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#AAA" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#BBB" Offset="0.0"/>
                    <GradientStop Color="#EEE" Offset="0.1"/>
                    <GradientStop Color="#EEE" Offset="0.9"/>
                    <GradientStop Color="#FFF" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />

        <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />

        <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />

        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" />

        <!-- Border Brushes -->

        <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#CCC" Offset="0.0"/>
                    <GradientStop Color="#444" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="HorizontalNormalBorderBrush" StartPoint="0,0" EndPoint="1,0">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#CCC" Offset="0.0"/>
                    <GradientStop Color="#444" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="DefaultedBorderBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#777" Offset="0.0"/>
                    <GradientStop Color="#000" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="PressedBorderBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#444" Offset="0.0"/>
                    <GradientStop Color="#888" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />

        <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />

        <SolidColorBrush x:Key="LightBorderBrush" Color="#AAA" />

        <!-- Miscellaneous Brushes -->
        <SolidColorBrush x:Key="GlyphBrush" Color="#444" />

        <SolidColorBrush x:Key="LightColorBrush" Color="#DDD" />

        <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <Border
      x:Name="Border" 
      Grid.ColumnSpan="2"
      CornerRadius="2"
      Background="{StaticResource NormalBrush}"
      BorderBrush="{StaticResource NormalBorderBrush}"
      BorderThickness="1" />
                <Border 
      Grid.Column="0"
      CornerRadius="2,0,0,2" 
      Margin="1" 
      Background="{StaticResource WindowBackgroundBrush}" 
      BorderBrush="{StaticResource NormalBorderBrush}"
      BorderThickness="0,0,1,0" />
                <Path 
      x:Name="Arrow"
      Grid.Column="1"     
      Fill="{StaticResource GlyphBrush}"
      HorizontalAlignment="Center"
      VerticalAlignment="Center"
      Data="M 0 0 L 4 4 L 8 0 Z"/>
            </Grid>
            <ControlTemplate.Triggers>
                <!--<Trigger Property="ToggleButton.IsMouseOver" Value="true">
                    <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
                </Trigger>-->
                <Trigger Property="ToggleButton.IsChecked" Value="true">
                    <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                    <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                    <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                    <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
            <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
        </ControlTemplate>

        <Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="MinWidth" Value="120"/>
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                        <Grid>
                            <ToggleButton 
            Name="ToggleButton" 
            Template="{StaticResource ComboBoxToggleButton}" 
            Grid.Column="2" 
            Focusable="false"
            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
            ClickMode="Press">
                            </ToggleButton>
                            <ContentPresenter
            Name="ContentSite"
            IsHitTestVisible="False" 
            Content="{TemplateBinding SelectionBoxItem}"
            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
            Margin="3,3,23,3"
            VerticalAlignment="Center"
            HorizontalAlignment="Left" />
                            <TextBox x:Name="PART_EditableTextBox"
            Style="{x:Null}" 
            Template="{StaticResource ComboBoxTextBox}" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Margin="3,3,23,3"
            Focusable="True" 
            Background="Transparent"
            Visibility="Hidden"
            IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Popup 
            Name="Popup"
            Placement="Bottom"
            IsOpen="{TemplateBinding IsDropDownOpen}"
            AllowsTransparency="True" 
            Focusable="False"
            PopupAnimation="Slide">
                                <Grid 
              Name="DropDown"
              SnapsToDevicePixels="True"                
              MinWidth="{TemplateBinding ActualWidth}"
              MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border 
                x:Name="DropDownBorder"
                Background="{StaticResource WindowBackgroundBrush}"
                BorderThickness="1"
                BorderBrush="{StaticResource SolidBorderBrush}"/>
                                    <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                    </ScrollViewer>
                                </Grid>
                            </Popup>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="HasItems" Value="false">
                                <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="true">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </Trigger>
                            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                                <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                            </Trigger>
                            <Trigger Property="IsEditable"
               Value="true">
                                <Setter Property="IsTabStop" Value="false"/>
                                <Setter TargetName="PART_EditableTextBox" Property="Visibility"    Value="Visible"/>
                                <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
            </Style.Triggers>
        </Style>

    </Window.Resources>

这篇关于如何在鼠标悬停样式ComboBox背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆