Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

WPF, Default Buttons and input

time to read 2 min | 222 words

I got the following bug report about NH Prof:

When renaming a session, the "enter" key seems to invoke the "Cancel" rather than the "Rename Session" button - this is slightly annoying (and unexpected) behavior.


But that is impossible, here is the XAML for this:


And as it turned out, the code is correct, and the explanation for the error is wrong, but the behavior exists.

The actual problem turned out to be that if you hit enter while the focus is on the text box, the RenameSession method will be called, but the bound value will not be modified, since the default binding mode for text boxes is on focus lost. We can fix this using:


Although this is logical, considering how WPF works, I still find it surprising, I would expect this to be a common scenario that would be handled OOTB.


Paulo Quicoli

WPF has 2 kinds of focus, Visual one and Keyboard one. These really sucks

Dan Plaskon

Hey..that bug report looks familar! Thanks for addressing this so quickly :)


I sometimes see WPF as a minefield, with issues such as these as the explosives. They each take a few hours to defuse and sometimes you end up having to put your developers back together again - usually it's just their hair, but it can be worse. We have morphine, in the form of coffee, on hand on the battlefield (dev room) at all times.

tomasz kubacki

I've made a couple of apps in WPF. The truth is it's simply overengineered.

Simple things made in Winforms can be extremly hard in WPF. WPF lacks of predefined good looking consistent styles, and it's internal logic makes it imposible to do an usable gui designer for it (if you think this one from vs2010 is good then..come on. can you make app without hand edited XAML? In forms it was possible)


@tomasz kubicki: I think you're not really right.

Andrew Borodin

And, as far as i know, there is a difference between default binding mode in xaml and c#.


Having made some critical comments, I must also add that I'm involved in writing a WPF app (Cradiator - http://cradiator.codeplex.com/ ) that takes advantage of WPF graphical features such that I would have no idea how to write the same app in WinForms.

Not only that, but it would likely be so difficult & painful, that I think it would be beyond my ability to convert it to WinForms (or Win32) - I rate WPF highly in this context. Yay for allowing me to write apps with graphical complexity that were previously out of my reach.


What I do for that is make an update binding on enter behavior and apply it to these sorts of fields. That way you aren't getting bound per key stroke and youg et the new value on enter.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats