Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF: Unable to set MouseOver effect for ComboBox

WPF: Unable to set MouseOver effect for ComboBox

Scheduled Pinned Locked Moved WPF
csharpdatabasewpfhelpquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    All Time Programming
    wrote on last edited by
    #1

    Hi, I have a Combobox, who gets Gradient blue color when mouse-over or clicked. I managed to change the color of selecting Items background, but the mouse over background color couldn't change.

       <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Border Name="bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Background}" Padding="2">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="bd" Property="Background" Value="#F7F7F7" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
    

    On adding the above code, MouseOver is definetely achieved i.e. Background color is changed on MouseOver. But with this, I can't see the drop down triagle icon or click the combobox that shows the drop down. What am I lacking and ho to achieve it ? Any help is highly appreciated.

    Thanks & Regards,

    I 1 Reply Last reply
    0
    • A All Time Programming

      Hi, I have a Combobox, who gets Gradient blue color when mouse-over or clicked. I managed to change the color of selecting Items background, but the mouse over background color couldn't change.

         <Setter Property="Template">
                  <Setter.Value>
                      <ControlTemplate TargetType="{x:Type ComboBox}">
                          <Border Name="bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Background}" Padding="2">
                              <ContentPresenter />
                          </Border>
                          <ControlTemplate.Triggers>
                              <Trigger Property="IsMouseOver" Value="True">
                                  <Setter TargetName="bd" Property="Background" Value="#F7F7F7" />
                              </Trigger>
                          </ControlTemplate.Triggers>
                      </ControlTemplate>
                  </Setter.Value>
              </Setter>
      

      On adding the above code, MouseOver is definetely achieved i.e. Background color is changed on MouseOver. But with this, I can't see the drop down triagle icon or click the combobox that shows the drop down. What am I lacking and ho to achieve it ? Any help is highly appreciated.

      Thanks & Regards,

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      When you set the Template property, you're basically replacing the entire control. In this case, you turned a ComboBox into a ContentControl by removing (not including) all of the things that made it a ComboBox. If all you want to change is the Background, then you should be putting this stuff directly in the Style.Triggers, not inside a Template. For example:

      <Style TargetType="ComboBox">
      <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="true">
      <Setter Property="Background" Value="Red"/>
      </Trigger>
      </Style.Triggers>
      </Style>

      Proud to have finally moved to the A-Ark. Which one are you in?
      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups