tags:

views:

59

answers:

2

I have a login window with a "Sign In" button which is set as the default button (IsDefault="True"). The sign in button is supposed to open a new window which also has a default button.

When the user hits the enter key, the Sign In button click event is raised and a new window is opened. But, for some reason the click event for the default button on the new window is also raised as soon as the window is opened.

This behavior is not observed if the user clicks the sign in button with the mouse or tabs to it and presses the space bar.

Any ideas on why this is happening or how to work around it?

NOTE: I tried setting the IsDefault=true in the new window's loaded event (instead of in xaml) but that didn't help.

A: 

I can't say exactly why is this happening, until I see your code. Could you create a small reproducible example?

Just worth to mention that IsDefault/IsCancel button implementation is based on AccessKeys mechanism, which is on of the most counter-intuitive part of the framework (imho).

I think you could get some kind of access key scopes collisions, or your repeat-key rate is tooo high, or maybe your Enter key just stuck :)?

You can read more about access keys and default buttons on Neil Mosafi's blog. Who knows, maybe you'll find an answer right there, in AccessKeyScoper.

Anvaka
A: 

Unfortunatly, there was a miscommunication. Apparently, the first window was not using IsDefault. Instead, the KeyUp Event on the window was watching for the enter key. Additionally, the e.Handled was not being set. This was causing the default button on the second window to handle the enter key press from the first window.

Kelly