The LostFocus event is only raised when other controls outside the (StackPanel in this situation) receives focus.
Example:
In the view you have your
StackPanel
and someTextBlock
controls.
In this case theLostFocus
event will not be raised sinceTextBlock
cannot gain FocusIn the view you have your
StackPanel
and someTextBox
controls or other input enabled controls.
In this case theLostFocus
event will be raised as soon as one of the other controls gainsFocus
.
Note:
If you don't have any TextBox
controls, there is a workaround by catching the Tap
event on the Container of the StackPanel
:
- When a
Tap
event occurs in the container, and the position is also in theStackPanel
area, theStackPanel
will catch the event and will not propagate it to the container. - When the Tap occurs outside of the
StackPanel
it will only be raised on the container or other controls present in the container (this is when yourStackPanel
losesFocus
).