Commit Focused Element in Silverlight
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 = FocusNavigationD开发者_C百科irection.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?
I'm assuming you want to update the source of a binding. If you're not, you probably should.
BindingExpression expression = textBox1.GetBindingExpression(TextBox.TextProperty);
expression.UpdateSource();
精彩评论