WPF, Default Buttons and input
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.
Comments
WPF has 2 kinds of focus, Visual one and Keyboard one. These really sucks
I had almost exactly the same problem some days ago,
just with the added complexity that I could not use OnPropertyChanged because that does not really work with FormatString bindings:
www.tigraine.at/.../beware-of-button-isdefaultt...
greetings Daniel
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.
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.
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