Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,972 | Comments: 44,523

filter by tags archive

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.


Comments

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 :)

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

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

@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#.

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
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.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. Production postmortem (5):
    29 Jul 2015 - The evil licensing code
  2. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
  3. API Design (7):
    20 Jul 2015 - We’ll let the users sort it out
  4. What is new in RavenDB 3.5 (3):
    15 Jul 2015 - Exploring data in the dark
  5. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats