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

Create RadMaskedNumericInput dynamically

2 Answers 41 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Maciej
Top achievements
Rank 1
Maciej asked on 23 Aug 2016, 09:53 PM

Hi,

I need to create a set of RadMaskedNumericInput dynamically in code. I have the following (working) code with WPF TextBox

            var textBox = new TextBox
            {
                Height = 23,
                Width = 40,
                Margin = new Thickness(recalculatedPoint.X, recalculatedPoint.Y, 0, 0),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            Binding bind = new Binding(bindingExpression)
            {
                Source = this,
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
            textBox.SetBinding(TextBox.TextProperty, bind);

 

When I change the control type from TextBox to RadMaskedNumericInput and binding property from TextBox.TextProperty to RadMaskedNumericInput.ValueProperty control is created but binding does not work.The code is:

            var textBox = new RadMaskedNumericInput
            {
                Height = 23,
                Width = 40,
                Margin = new Thickness(recalculatedPoint.X, recalculatedPoint.Y, 0, 0),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            Binding bind = new Binding(bindingExpression)
            {
                Source = this,
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
            textBox.SetBinding(RadMaskedNumericInput.ValueProperty, bind);

 

Has anyone an idea why binding does not work?

Thanks in advance.

Have a nice day

 

2 Answers, 1 is accepted

Sort by
0
Maciej
Top achievements
Rank 1
answered on 24 Aug 2016, 01:43 PM

It turned out that with additional styles it is working properly.

                IsClearButtonVisible = false,
                Placeholder = ' ',
                FormatString = "{}{0:0}"

 

0
Martin Ivanov
Telerik team
answered on 26 Aug 2016, 07:07 AM
Hi Maciej,

It is good to hear that you managed to achieve what you were looking for. As a side note, keep in mind that the Value property of RadMaskedNumericInput works with nullable double (double?) values and in some cases if you bound a string, it is possible that the control doesn't behave as expected.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Maciej
Top achievements
Rank 1
Answers by
Maciej
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or