Handle click outside window in ShowDialog

5 posts, 0 answers
  1. Kevin
    Kevin avatar
    30 posts
    Member since:
    Jul 2012

    Posted 22 Apr 2011 Link to this post

    I would like to allow the user to close the RadWindow in ShowDialog() mode by clicking outside of the window.  I know I can set the color of this background area using the ModalBackground property... but is there a way to handle a mouse click on this?

    Thanks for the help!
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 27 Apr 2011 Link to this post

    Hello Kevin,

    There is no easy way to achieve this. You have to find the Rectangle which illustrates the modal background and hook to its mouse click event. The modal background is created dynamically, so you will have to find the visual parent of the RadWindow.

    Hope this information helps.

    Regards,
    Konstantina
    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. Tom
    Tom avatar
    11 posts
    Member since:
    Jan 2012

    Posted 07 Feb 2012 Link to this post

    I was looking for a solution to this problem and found that the object you are looking for is in fact a Canvas.
  5. Tom
    Tom avatar
    11 posts
    Member since:
    Jan 2012

    Posted 08 Feb 2012 Link to this post

    Upon further exploration I have come up with a solution that works well. Hopefully someone will find it useful:

    RadWindow PopupWindow;
    public SampleView()
    {
        InitializeComponent();
        PopupWindow = new RadWindow { Header = "Details", Name = "radWindow" };
        PopupWindow.Loaded += new RoutedEventHandler(PopupWindow_Loaded);
    }
    void PopupWindow_Loaded(object sender, RoutedEventArgs e)
    {
        Canvas canvas = Framework.Traversal.FirstVisualAncestorOfType<Canvas>(PopupWindow);
        canvas.MouseLeftButtonDown -= canvas_MouseLeftButtonDown;
        canvas.MouseLeftButtonDown += canvas_MouseLeftButtonDown;
    }
    void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        Point mousepoint = e.GetPosition(null);
        var elements = VisualTreeHelper.FindElementsInHostCoordinates(mousepoint, PopupWindow);
        if (elements.Count() == 0)
            PopupWindow.Close();
    }
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 13 Feb 2012 Link to this post

    Hello Tom,

    Thank you for sharing your solution with the community.

    Greetings,
    Konstantina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft banner