Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force LostFocus when button is clicked

Tags:

xaml

XAML C# not WEB page is a Window

At the click of a button I:

  1. Need to trap the name of the last control OnFocus
  2. Force the LostFocus event of the control.
like image 781
ramnz Avatar asked Jul 30 '10 17:07

ramnz


1 Answers

// PROBLEM: clicking on btns does not force lostfocus event on the last entered element control (last entry control could be text,checkbox or others) added save button, where calling such method it moves focus to parent forcing lostfocus on last element.

    private void btnSave_Click(object sender, RoutedEventArgs e)
    {
        AcceptLastFocusedElement(sender, e);
    }


    private void AcceptLastFocusedElement(object sender, RoutedEventArgs e)
    {
        FocusManager.SetFocusedElement(this, (Button)sender);
    }

NOTE: no need for task number 1 (getting the name of the element).

like image 94
ramnz Avatar answered Oct 21 '22 09:10

ramnz