Clearing numberic with MVVM approach

2 posts, 0 answers
  1. band
    band avatar
    37 posts
    Member since:
    Jun 2016

    Posted 24 Feb 2017 Link to this post

    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?

  2. Dinko
    Dinko avatar
    522 posts

    Posted 28 Feb 2017 Link to this post

    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:
     <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.

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top