Close Drop Down

5 posts, 0 answers
  1. Jason Clark
    Jason Clark avatar
    8 posts
    Member since:
    Mar 2005

    Posted 10 Feb 2010 Link to this post

    Is it possible to close the drop down on mouseleave or something similar?

    Thanks
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Feb 2010 Link to this post

    Hello Jason,

    RadComboBox cannot close its dropdown automatically when the mouse leaves it, but you could try to hook a handler on the MouseLeave event and when the e.OriginalSource == sender (e.g. the RadComboBox) you could set IsDropDownOpen = false.

    Kind regards,
    Valeri Hristov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. kwitee
    kwitee avatar
    3 posts
    Member since:
    Feb 2012

    Posted 10 Feb 2012 Link to this post

    Hi, I am trying to do something similar:
    I want to close the RadDropDownButton when the mouse leaves the button OR the DropDownContent. But when the mouse 
    leaves the button and enters the DropDownContent, it should stay open. 
    Is there a simple way to do it?  

    -- regards, 
    kwitee
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 15 Feb 2012 Link to this post

    Hello Ondra,

     One way to achieve this scenario is to use a DispatcherTimer and couple of bool flags:

    <telerik:RadDropDownButton x:Name="dropDownButton" Content="DropDownButton" MouseLeave="DropDownButton_MouseLeave" MouseEnter="DropDownButton_MouseEnter">
        <telerik:RadDropDownButton.DropDownContent>
            <Grid Width="200" Height="200" Background="LightGreen" MouseEnter="Content_MouseEnter" MouseLeave="Content_MouseLeave" />
        </telerik:RadDropDownButton.DropDownContent>
    </telerik:RadDropDownButton>

    using System;
    using System.Linq;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Threading;
     
    public partial class MainPage : UserControl
    {
        private bool buttonMouseInside, contentMouseInside;
     
        DispatcherTimer timer = new DispatcherTimer();
     
        public MainPage()
        {
            this.InitializeComponent();
     
            this.timer.Interval = TimeSpan.FromSeconds(0.5);
            this.timer.Tick += new EventHandler(Timer_Tick);
        }
     
        private void CloseDropDownButton()
        {
            this.timer.Stop();
            this.timer.Start();
        }
     
        private void Content_MouseEnter(object sender, MouseEventArgs e)
        {
            this.contentMouseInside = true;
        }
     
        private void Content_MouseLeave(object sender, MouseEventArgs e)
        {
            this.contentMouseInside = false;
            this.CloseDropDownButton();
        }
     
        private void DropDownButton_MouseEnter(object sender, MouseEventArgs e)
        {
            this.buttonMouseInside = true;
        }
     
        private void DropDownButton_MouseLeave(object sender, MouseEventArgs e)
        {
            this.buttonMouseInside = false;
            this.CloseDropDownButton();
        }
     
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (!this.buttonMouseInside && !this.contentMouseInside)
            {
                this.dropDownButton.IsOpen = false;
            }
        }
    }

    Give it a try and let me know if this approach suites your scenario.

    Greetings,
    Kiril Stanoev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. kwitee
    kwitee avatar
    3 posts
    Member since:
    Feb 2012

    Posted 15 Feb 2012 Link to this post

    Hi, 
    your solution works fine for me. It was a little glitchy at first, but with smaller timer interval (0.2 sec) and negativ content top-margin it works like I wanted. 
    Thanks a lot. 

    -- regards
    kwitee



Back to Top
DevCraft banner