This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I'm currently evaluating WPF Elements to find if it meets our needs and am largely impressed with it. However, so far I have been unable to make NumericTextBoxes function in the manner we need. Namely, I need a way to display only a certain number of digits of double value when not in edit mode, but allow the user to input decimal digits freely. I noticed that there is a Precision property on IntegerTextBox that functions similarly to this, but cannot find an analog for doubles. If there isn't a built in functionality for this, is it possible to simply make an attached behavior that filters the Text property of the control as we desire it (trimming extra digits for example) without truncating the stored Value property? |
|
|
Firstly thank you for trying WPF Elements and for bringing this matter to our attention. As you no doubt have noticed there is currently an issue surrounding the handling of the Precision property on the NumericTextBox control; we are investigating and will notify yourself when a fix is available in the nightly builds. Regarding your enquiry while there is currently no ‘edit mode/display mode’ functionality allowing precision to dynamically change, as it is indeed desirable we will look into it. Regarding the behavior of this, are you looking to round the decimal/double or simply display a truncated version of the Value to the user? |
|
|
Simply displaying a truncated version would be best for our current needs, but I can certainly see the utility of rounding/truncating values in the control for some purposes. Thanks for the quick response! |
|
|
Hello We have added an option to the NumericTextBox control to enable the behaviour you have described. This option can be downloaded from the next nightly builds which will be available around 1200 GMT. Nightly builds can be found on the downloads page: https://www.mindscapehq.com/products/wpfelements/nightly-builds When you get this nightly build, set the DecimalPlaces property to be the number of decimal places you want to be displayed when not in edit mode. Set the EnforceDecimalPlaces property to be false which will allow the user to type as many decimal places as they want. Then set the new FocusChangedBehavior property to be Round. This will round the displayed value based on the DecimalPlaces property when the control loses focus. When the control regains focus, the users previous input will be restored to full precision allowing them to continue editing. Try this out and let us know if it produces the behaviour you were expecting, and let us know if any details need to be revised. Jason Fauchelle |
|
|
That's great, thank you! Your quick response is impressive. An additional behavior we intend to implement is a so-called 'Dynamic Decimal Digits', where numbers don't display decimal digits if they lack them. This is nice for our purposes as inputs may vary over eight or more orders of magnitude. Can we simply subscribe to the FocusChanged event and set the DecimalPlaces property in code? More precisely, will the Round behavior occur before or after the FocusChanged event is fired? Previously our DynamicDecimalDigitsBehavior worked like such:
Curious if basically the same thing will work here. |
|
|
Hello I've experimented with this, and the best way I have found to implement 'Dynamic Decimal Digits' with the NumericTextBox is using this code:
The NumericTextBox_ValueChanged method is attached to the ValueChanged event of the NumericTextBox. (I tried listening to the LostFocus event, but ValueChanged was easier to get the right behaviour) Using this code, if the NumericTextBox loses focus, the DecimalPlaces property will be changed based on the current value. If there are no digits after the decimal point, then the DecimalPlaces will be set to zero and so on. I've included the Math.Min statement so there can be a maximum of 2 decimal points when not in edit mode. This ensures that the previous behaviour you requested still works. You can use this code as it is without needing to download a nightly build. Try it out and let me know if it produces the expected behaviour or if I have misunderstood something. Jason Fauchelle |
|
|
That is perfect. Thanks! |
|