A while back I posted a revision
to my original default button sample that made it a bit easier to use, but there was still an issue... If you invoke the button while the focus is still in a text box, any changes made to the text in the text box may not get pushed into the databinding source, since by default that happens when the text box loses focus. I didn't come up with a good solution, but luckily somebody did. :) I got the following revision from Glenn Orr, and this should solve the problem. If you have any custom data entry controls, etc. you may have to add additional clauses to handle them, but this will work with text boxes for sure.
Change the OnKeyUp method to look like this...
private void OnKeyUp(object sender, KeyEventArgs arg)
if (arg.Key == Key.Enter)
if (peer != null)
if (sender is TextBox)
BindingExpression expression = (sender as TextBox).GetBindingExpression(TextBox.TextProperty);
This will make sure that any changes get pushed into the databinding source before the button is invoked.