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

radmaskednumericinput two way binding doesn't work

5 Answers 219 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
rachel
Top achievements
Rank 1
rachel asked on 07 Oct 2014, 06:01 AM
Hi,

I have a radmaskednumericinput which is binded two way to a property, but there is a problem, when focusing the textbox, the value from code is overided with zero.

Thanks,
Rachel.

5 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 08 Oct 2014, 01:45 PM
Hello Rachel,

There are many details that can affect the behavior of the MaskedInput control. Given only the provided information we are not able to track-down the cause of the issue.

Can you elaborate more on your scenario by sending us a sample project which isolates the issue or a code snippet. It is important to know the Mask token you used for the Mask property, the ViewModel and the property to which you bound the Value of the RadNumericMaskedInput. This will allow us to test it locally and further investigate the reason behind this behavior.

Thank you in advance for your cooperation.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
rachel
Top achievements
Rank 1
answered on 19 Oct 2014, 04:11 AM
Hi,
I do not manage to attache a sample project, so i will write the view and view model  here:
 VM:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication5
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window,INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private decimal? _num=1;

        public decimal? Num
        {
            get { return _num; }
            set { _num = value; onPropertyChanged("Num"); }
        }


        public void onPropertyChanged(string name)
        {
            if(PropertyChanged!=null)
                PropertyChanged(this,new PropertyChangedEventArgs(name));
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}

View:

<Window x:Class="WpfApplication5.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:maskedInput="clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
      
        <Style x:Key="RadMaskedInputBaseStyle" TargetType="{x:Type telerik:RadMaskedInputBase}">
            <Setter Property="Padding" Value="6"/>
            <Setter Property="Margin" Value="10"/>
            <Setter Property="Height" Value="28"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Background" Value="White" />
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="IsTabStop" Value="True"/>
            <Setter Property="SelectionOnFocus" Value="SelectAll"/>
            <Setter Property="TextMode" Value="MaskedText"/>
            <Setter Property="InputBehavior" Value="Insert"/>
            <Setter Property="SpinMode" Value="None"/>
        </Style>
        <Style  TargetType="{x:Type telerik:RadMaskedNumericInput}"
           BasedOn="{StaticResource RadMaskedInputBaseStyle}">
            <Setter Property="Mask" Value=""/>
            <Setter Property="AllowSkipPlaceholders" Value="False"/>
            <Setter Property="AutoFillZeros" Value="False"/>
            <Setter Property="AutoFillNumberGroupSeparators" Value="False"/>
            <Setter Property="Placeholder" Value=" "/>
            <Setter Property="SectionsNavigationMode" Value="None"/>
            <Setter Property="IsReadOnly" Value="False"/>
            <Setter Property="maskedInput:MaskedInputExtensions.Minimum" Value="0"/>
        </Style>

    </Window.Resources>
    <StackPanel>

         <!--decimal-->
        <telerik:RadMaskedNumericInput  AutoFillZeros="False" UpdateValueEvent="PropertyChanged"  Height="100" Width="400" InputBehavior="Insert"  AllowInvalidValues="True"   maskedInput:MaskedInputExtensions.Minimum="-79228162514264337593543950335M" maskedInput:MaskedInputExtensions.Maximum="79228162514264337593543950335M"  IsClearButtonVisible="False" Text="{Binding Num,RelativeSource={RelativeSource AncestorType=Window},Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions = true,TargetNullValue=9}"/>
    </StackPanel>
</Window>

Thanks,
Rachel.




0
Milena
Telerik team
answered on 22 Oct 2014, 11:00 AM
Hello Rachel,

Тhank you for the code snippet.

Actually you should use the Value property of the RadMaskedNumericInput instead of Text property. The Text property is used only to display the text representation of the value when the control isn't focused. More about Text and TextMode properties you can read in out help topic Common

I hope this information is helpful. 

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
rachel
Top achievements
Rank 1
answered on 23 Oct 2014, 07:50 AM
Hi,

Thanks, it works now' but i have another question regarding the previous code, I do not manage to enter negetive nums, i get an exception.

Thanks,
Rachel.
0
Milena
Telerik team
answered on 24 Oct 2014, 11:10 AM
Hello Rachel,

The exception is thrown because you have set:
<telerik:RadMaskedNumericInput
maskedInput:MaskedInputExtensions.Minimum="-79228162514264337593543950335M" .../>

When you set this value in Xaml there is no need to add "M" at the end of the value for Decimal types (only in code behind). 

Also, please have in mind that the value of RadMaskedNumericInput is of type Double? (nullable Double). If you need to use Decimal, then it is better to use RadMaskedCurrencyInput.

We remain available in case you may need additional information.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
rachel
Top achievements
Rank 1
Answers by
Milena
Telerik team
rachel
Top achievements
Rank 1
Share this question
or