This project has moved and is read-only. For the latest updates, please go here.

CalculatorUpDown problem with SelectAllGotFocus and EnterClosesCalculator

Dec 8, 2012 at 6:35 PM

I am trying to use a CalculatorUpDown (v1.8) in a simple project but can't seem to get it to work.

The property SelectAllGotFocus does not seem to have any effect at all - setting it to true does nothing. I haven't looked into this as of yet.

The EnterClosesCalculator property also doesn't do anything, but I've done a little digging on this (with the latest downloadable source).  



to the CalculatorUpDown.cs line 183:

private void OnKeyDownobject senderKeyEventArgs e )

method reveals that the control is handling keypresses, but the enter (or return) keys do not fire the event at all.

I've tested this is VS2010 and VS2012 using .NET 4 & 4.5


I'm still pretty new to WPF so I'm not sure I can figure out the root of the problem myself, but I'll post any results I find.

Dec 8, 2012 at 7:05 PM
Edited Dec 8, 2012 at 9:09 PM

Ok - It looks like the ancestor base class UpDownBase is eating the KeyDown event (e.Handled=True) if the return key is pressed.

My solution to this was to override the base class OnKeyDown, calling the base class method within, then calling the CalculatorUpDown OnKeyDown handler.. It looks like this:

public CalculatorUpDown()
  //Keyboard.AddKeyDownHandler( this, OnKeyDown1 );
  Mouse.AddPreviewMouseDownOutsideCapturedElementHandler( this, OnMouseDownOutsideCapturedElement );

protected override void OnKeyDown(KeyEventArgs e) {
  e.Handled = false; // needed to allow the calculator part to process this as an =
  OnKeyDownLocal(this, e);

private void OnKeyDownLocal( object sender, KeyEventArgs e )
  switch( e.Key )
... (original code continues)

I'm not sure this is the best way to go about it, but it does seem to work.

Dec 10, 2012 at 4:51 PM

An issue has been created in order to adress theses bugs:

Dec 11, 2012 at 1:59 PM

All this will be fixed in version 1.9