xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.87k stars 873 forks source link

Force calculator to calculate #972

Open xceedsoftware opened 7 years ago

xceedsoftware commented 7 years ago

jkshay[CodePlex]
I'm using the Calculator in a pop-up window. User is able to enter value into textbox. If detailed calculations are required, user can press calculator button and calculator appears (prefilled with any value entered into the textbox). User can then use calculator to manipulate values. Closing the pop-up window I want the resulting value to be pushed back into the textbox.

My problem is that I don't see any way to currently force the calculator to calculate. For example, if the user enters quot8quot, quot/quot, quot2quot, then closes the dialog (not completing the calculation), then the value returned is quot2quot.

I've tried calling Calculator.SetCalculatorButtonType(this.Calculator, Calculator.CalculatorButtonType.Equal);

However, I receive a null reference exception in the toolkit.dll when I do.

Is it possible to programmatically force the calculator to quotcalculatequot?

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Hi,

You can set the FontSize directly on the CalculatorUpDown : xctk:CalculatorUpDown Watermark=Data FontSize=22/ Or if you want to modify the template, you can find it here : -Xceed.Wpf.Toolkit/CalculatorUpDown/Themes/Aero2.NormalColor.xaml (For windows8) -Xceed.Wpf.Toolkit/CalculatorUpDown/Themes/Generic.xaml (For other Windows)

xceedsoftware commented 7 years ago

jkshay[CodePlex]
Thanks for the tip. Using the CalculatorUpDown (of whose existence I was not previously aware) seems to be a much better solution for my scenario.

Currently I'm working on templating the watermark, but I'm curious: Is the template of the textbox available for modification? I'd like to change the font size to match my other textboxes.

Thanks!

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Hi,

I can understand why you want to complete the operation on the calculator when closing the Popup, but the calculator is not showing the result at this moment. It is showing the last digit pressed.

If I compare with a real calculator, doing 8 / 2 and puting the calculator away won't give me an answer. I think user must complete its operation before closing the popup. User could want to do 8 / 2 * 6 before pressing Equal.

You can also try the CalculatorUpDown instead of creating a textBox and a button showing a calculator.

da-jokker commented 4 years ago

Along these same lines, I also have a similar issue. As for the OP, I do the same but simply trap the KeyUp on the Calculator.

if (e.Key == Key.Escape) { this.DialogResult = false; this.Close(); } else if (e.Key == Key.Enter) { this.DialogResult = true; this.Close(); }

So when my Calc "pop up window" opens, if I type 8/2 and press enter (all keyboard), the Calculator totals up the value, my pop up closes, then on the parent window I just grab the Calculator Value.

Which brings me to my issue... I know this is odd, but if I open the Calculator type in a value and then press enter, the "Value" is 0. It appears that the Value is not set until an actual operation occurs.

I would like either access to the calculators "screen" so I could grab what is being displayed, or when the Calculator is either closing, or even if I triggered the "=" key ... something that would set the Value so I can retrieve it.

XceedBoucherS commented 4 years ago

Hi, As you pointed out, the Value is set when the operation occurs. If you want to access the text in the screen of the Calculator, you can use the property Calculator.DisplayText, which is a string.