LostFocus event - the event which fires when your TextBox loses focus.
See more info in the official documentation, but it's basically very simple - use it like any other event handler.
If you need to know that the keyboard has been closed, make sure that no other input control received focus at the same time your TextBox lost it.