I need code that will force Silverlight to commit the focused element (in my case a TextBox, but it could be anything). In WPF I use
public static void CommitFocusedElement() {
UIElement element = Keyboard.FocusedElement as UIElement;
if (element != null) {
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
FocusNavigationDirection directionBack = FocusNavigationDirection.Previous;
if (!element.MoveFocus(request)) {
request = new TraversalRequest(FocusNavigationDirection.Previous);
directionBack = FocusNavigationDirection.Next;
element.MoveFocus(request);
}
if (element.Focusable)
{
element.Focus();
}
else
{
element.MoveFocus(new TraversalRequest(directionBack));
}
}
}
But several parts of this code is not Silverlight compatible. Can anyone point me to a Silverlight alternative?
Thanks.