This is a migrated thread and some comments may be shown as answers.

Clearing numberic with MVVM approach

1 Answer 107 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
band
Top achievements
Rank 1
band asked on 24 Feb 2017, 05:22 PM

Hi simple question, I know you can clear the numeric approach in behind code using something like this 

 

    <telerik:RadButton Content="Clear" Command="{Binding ElementName=RMTI,Path=ClearCommand}"/>

 

But I'm looking for an MVVM approach. Any ideas? 

 

In my viewmodel I would set the NumericTextBox value to null but instead of clearing out, it would go to zero. NumericTextBox Value is of type double?

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 28 Feb 2017, 03:57 PM
Hello Band,

From the last sentence is not exactly clear which type of type you are using: RadMaskedNumericInput or RadMaskedTextInput. Can you confirm which type you are using?

If we have correctly understood your scenario you are trying to set the mask to zero instead of null when you clear the mask. If this is the case, you can use the MaskedInputExtensions class and set the AllowNull attached property to False. This way when the ClearCommand of the mask has executed the value will be set to zero. Basically, binding a button to the ClearCommand of the mask will not break the MVVM pattern. Here is the sample code:
xmlns:maskedInput="clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input"
 
 <telerik:RadMaskedNumericInput Value="{Binding MaskValue}"  maskedInput:MaskedInputExtensions.AllowNull="False" />
You can take a look at the MaskedInputExtensions help article where this class is further described.

Regards,
Dinko
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
band
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or