none
Mouse Over Events in WPF

    Question

  • Hi,

    I have one ComboBox.When i move the mouse near the ComboBox,the ComboBox have to show the Containing Data without user clicks on ComboBox.Can we do this.


    PS.Shakeer Hussain
    Sunday, January 02, 2011 11:19 AM

Answers

  • Hi there,

    whoa, you're right! That is, while my Trigger works, it'll work only once (uh, the OP didn't ask for an approach that would work at all times, huh? :-). Well, I had to spend quite some time on this in order to get it working. That is, besides the fact that there is a problem with the Trigger, I also wanted to not only have the cbo open when hovering over it, but also to have it be closed again when the mouse leaves the control.

    To cut a long story short, I've created a blog-post that shows how to create an attached behavior that seems do the trick.
    Here's the post: http://www.blogs.intuidev.com/post/2011/01/02/ComboBox_AutoOpenDropDown_AttachedBehavior.aspx


    Cheers,
    Olaf
    http://blogs.intuidev.com
    Sunday, January 02, 2011 6:51 PM
  • Hi Shakeer,

    you can use a Style along with a Trigger to achieve that:

    <ComboBox>
      <ComboBox.Resources>
       <Style TargetType="{x:Type ComboBox}">
         <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="IsDropDownOpen" Value="True" />
          </Trigger>
         </Style.Triggers>
       </Style>
      </ComboBox.Resources>
      <ComboBoxItem>Item #1</ComboBoxItem>
      <ComboBoxItem>Item #2</ComboBoxItem>
      <ComboBoxItem>Item #3</ComboBoxItem>
      <ComboBoxItem>Item #4</ComboBoxItem>
      <ComboBoxItem>Item #5</ComboBoxItem>
    </ComboBox>
    
    


    Cheers,
    Olaf
    http://blogs.intuidev.com
    Sunday, January 02, 2011 11:29 AM

All replies

  • Hi Shakeer,

    you can use a Style along with a Trigger to achieve that:

    <ComboBox>
      <ComboBox.Resources>
       <Style TargetType="{x:Type ComboBox}">
         <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="IsDropDownOpen" Value="True" />
          </Trigger>
         </Style.Triggers>
       </Style>
      </ComboBox.Resources>
      <ComboBoxItem>Item #1</ComboBoxItem>
      <ComboBoxItem>Item #2</ComboBoxItem>
      <ComboBoxItem>Item #3</ComboBoxItem>
      <ComboBoxItem>Item #4</ComboBoxItem>
      <ComboBoxItem>Item #5</ComboBoxItem>
    </ComboBox>
    
    


    Cheers,
    Olaf
    http://blogs.intuidev.com
    Sunday, January 02, 2011 11:29 AM
  • This works if the user hovers the mouse over the element, but the MouseLeave event won't be triggered if the pointer leaves the element. This is an issue if the user wants the drop down menu to close when the mouse is outside the element. The user has to click somewhere on the container or hit Tab + Enter.
    Sunday, January 02, 2011 12:39 PM
  • Hi there,

    whoa, you're right! That is, while my Trigger works, it'll work only once (uh, the OP didn't ask for an approach that would work at all times, huh? :-). Well, I had to spend quite some time on this in order to get it working. That is, besides the fact that there is a problem with the Trigger, I also wanted to not only have the cbo open when hovering over it, but also to have it be closed again when the mouse leaves the control.

    To cut a long story short, I've created a blog-post that shows how to create an attached behavior that seems do the trick.
    Here's the post: http://www.blogs.intuidev.com/post/2011/01/02/ComboBox_AutoOpenDropDown_AttachedBehavior.aspx


    Cheers,
    Olaf
    http://blogs.intuidev.com
    Sunday, January 02, 2011 6:51 PM
  • Hi Olaf,

    Yes, I think you have achieve your goal totally.

    Thank you very much for sharing it with us here.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 04, 2011 7:10 AM
  • hi :)

    i have a similar problem...i would like to show a lable which describes the button which i'm pointing at with the mouse. i'm new in wpf and don't know how to use mouseover.

    please help me :(

    Tuesday, January 18, 2011 7:20 PM
  • This one solves it straight forward in Xaml, hope it helps anyone having the same problem.

                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="IsDropDownOpen" Value="False"/>
                        <Style.Triggers>
                            <EventTrigger RoutedEvent="ComboBox.MouseEnter">
                                <BeginStoryboard>
                                    <Storyboard >
                                        <BooleanAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(ComboBox.IsDropDownOpen)">
                                            <DiscreteBooleanKeyFrame
                                                KeyTime="00:00:00"
                                                Value="True" />
                                        </BooleanAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </Style.Triggers>


    Regards Vallarasu S. BreakingDotNet.blogspot.com

    Wednesday, July 31, 2013 12:14 PM