I use the following method to dismiss the SIP:
///
/// Dismisses the SIP by focusing on an ancestor of the current element that isn't a
/// TextBox or PasswordBox.
///
public static void DismissSip()
{
var focused = FocusManager.GetFocusedElement() as DependencyObject;
if ((null != focused) && ((focused is TextBox) || (focused is PasswordBox)))
{
// Find the next focusable element that isn't a TextBox or PasswordBox
// and focus it to dismiss the SIP.
var focusable = (Control)(from d in focused.Ancestors()
where
!(d is TextBox) &&
!(d is PasswordBox) &&
d is Control
select d).FirstOrDefault();
if (null != focusable)
{
focusable.Focus();
}
}
}
The Ancestors
method comes from LinqToVisualTree by Colin Eberhardt. The code is used in conjunction with an Enter key handler, for "tabbing" to the next TextBox or PasswordBox, which is why they're skipped in the selection, but you could include them if it makes sense for you.