locked
LostFocus not being call when the application bar icon gets clicked RRS feed

  • Question

  • Hello, I have noticed that if you have a TextBox binded to a model (two way) with a default trigger and an application bar icon button, if you enter something to that textbox and then click on the app bar icon, the event LostFocus does not get called and that causes the "model" to be out of sync with the UI (data binding is push back to the model after the textbox looses the focus) Any ideas on how to overcome this?... Thanks!
    Tuesday, November 9, 2010 1:04 AM

Answers

  • I believe I have solved my problem; I put the following code in the AppBar routine. Just disables AppBar until TextBox loses focus (and keyboard disappears). var focusedElement = FocusManager.GetFocusedElement() as TextBox; if (focusedElement != null) { return; } So far, so good. Maybe of some help to you.
    Saturday, November 13, 2010 8:58 PM

All replies

  • I have a similar situation - TextBox event LostFocus is not triggered by AppBar. I suppose that's a reasonable result - AppBar is not necessarily the same as off-focus. But then, is it possible to determine the on-focus TextBox and run its LostFocus from the AppBar? Or would that be bad practice?
    Saturday, November 13, 2010 7:03 PM
  • I believe I have solved my problem; I put the following code in the AppBar routine. Just disables AppBar until TextBox loses focus (and keyboard disappears). var focusedElement = FocusManager.GetFocusedElement() as TextBox; if (focusedElement != null) { return; } So far, so good. Maybe of some help to you.
    Saturday, November 13, 2010 8:58 PM
  • Hi,

    I will combine your answer with the one of post http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/8c63172f-05af-4ed1-b787-217de9678d18/  and give this code in vb this time :

    Dim focusedElement As Control = FocusManager.GetFocusedElement()
            If focusedElement IsNot Nothing Then
                focusedElement.GetBindingExpression(TextBox.TextProperty).UpdateSource()
            End If
    Hope this could help


    Faical SAID Highwave Creations


    • Proposed as answer by Faical Saturday, November 24, 2012 9:55 AM
    • Edited by Faical Saturday, November 24, 2012 9:59 AM Better Solution
    Saturday, November 24, 2012 9:53 AM