Ayende @ Rahien

Refunds available at head office

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.

image 

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

image

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:

image 

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.

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Paulo Quicoli
09/21/2010 10:33 AM by
Paulo Quicoli

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

Dan Plaskon
09/21/2010 01:01 PM by
Dan Plaskon

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

PandaWood
09/22/2010 03:38 AM by
PandaWood

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
09/22/2010 05:52 AM by
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)

Frank
09/22/2010 08:55 AM by
Frank

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

Andrew Borodin
09/22/2010 11:33 AM by
Andrew Borodin

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

PandaWood
09/23/2010 01:17 AM by
PandaWood

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.

pb
09/25/2010 11:07 PM by
pb

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.

Comments have been closed on this topic.