Create RadMaskedNumericInput dynamically

3 posts, 0 answers
  1. Maciej
    Maciej avatar
    8 posts
    Member since:
    Nov 2015

    Posted 23 Aug Link to this post

    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. Maciej
    Maciej avatar
    8 posts
    Member since:
    Nov 2015

    Posted 24 Aug in reply to Maciej Link to this post

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

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

     

  3. UI for WPF is Visual Studio 2017 Ready
  4. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 26 Aug Link to this post

    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.
Back to Top