Radwindow + Focus

4 posts, 0 answers
  1. erawan
    erawan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 18 Aug 2010 Link to this post

    Hi,

    is it possible to make losing focus programatically on a window?

    like this:

    window1.GotFocus += new routedeventhandler(window1_GotFocus);
    window2.GotFocus += new ...( window2_GotFocus);


    void window1_GotFocus(...)
    {
    // lose window2 focus
    }


    void window2_GotFocus(...)
    {
    // lose window1 focus
    }


    Because right now, I have 2 Radwindow, but when I have focus on one and when I click on the other I don't lose the focus of the first RadWindow. How I know that? Because I have this code:

    window1.GotFocus += new routedeventhandler(window1_GotFocus);
    window1.LostFocus += new routedeventhandler(window1_LostFocus);
    window2.GotFocus += new routedeventhandler( window2_GotFocus);

    window2.LostFocus += new routedeventhandler(window2_LostFocus);

    void window1_GotFocus(object sender, routedeventargs e)
    {
                var window = sender as RadWindow;
                if (window != null && window.IsActiveWindow)
                {
                    mytextblos.Text += "\ngot focus fenetre 1";
                   
                }
    }

    void window1_LostFocus(object sender, routedeventargs e)
    {
                var window = sender as RadWindow;
                if (window != null && !window.IsActiveWindow)
                {
                    mytextblos.Text += "\nLostfocus fenetre 1";
                   
                }
    }

    void window2_GotFocus(object sender, routedeventargs e)
    {
                var window = sender as RadWindow;
                if (window != null && window.IsActiveWindow)
                {
                    mytextblos.Text += "\ngot focus fenetre 2";
                   
                }
    }

    void window2_LostFocus(object sender, routedeventargs e)
    {
                var window = sender as RadWindow;
                if (window != null && !window.IsActiveWindow)
                {
                    mytextblos.Text += "\nLostfocus fenetre 2";
                   
                }
    }

    but sometimes the "lostfocus fenetre i" doesn't work.....

    Please help !

    Erawan
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 20 Aug 2010 Link to this post

    Hello Erawan,

     When the focus is moved to another window, the one that owned the focus previously looses it first and then the new owner receives it. Please refer to the attached example that demonstrates this behavior.

    Please let me know if I don't understand the issue correctly.

    Regards,
    Miroslav Nedyalkov
    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. erawan
    erawan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 20 Aug 2010 Link to this post

    Thanks a lot.

    But I tried your code. It works no pb.

    But when I try to call any function, I lost the focus on the window.

    My code:

    window1.GotFocus += new RoutedEventHandler(window1_GotFocus);
    window1.LostFocus += new RoutedEventHandler(window1_LostFocus);

    window2.GotFocus += new RoutedEventHandler(window2_GotFocus);
    window2.LostFocus += new RoutedEventHandler(window2_LostFocus);


    void window1_GotFocus(object sender, RoutedEventArgs e)
    {
    var window = sender as RadWindow;
    events.Items.Add("got focus window1")
    window.Style = window.Resources["SecondStyle"] as Style;
    }

    void window1_LostFocus(object sender, RoutedEventArgs e)
    {
    var window = sender as RadWindow;
    events.Items.Add("lost focus window1")
    window.Style = window.Resources["FirstStyle"] as Style;
    }


    void window2_GotFocus(object sender, RoutedEventArgs e)
    {
    events.Items.Add("got focus window2")
    }

    void window2_LostFocus(object sender, RoutedEventArgs e)
    {
    events.Items.Add("lost focus window2")
    }




    where FirstStyle and SecondStyle are 2 styles that I created.
    and when I click on the firstwindow, I got the focus, but I lose it :

    got focus window1 ( clicking window1)
    lost focus window1

    got focus window2 ( clicking window2)

    lost focus window2 ( clicking window1)
    got focus window1
    lost focus window1
  5. George
    Admin
    George avatar
    1332 posts

    Posted 25 Aug 2010 Link to this post

    Hi Erawan,

    If you want to change the style for the RadWindow when is focused and when it's not, I suggest you to create states instead of setting styles.

    I hope this helps.

    Greetings,
    George
    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
Back to Top