Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. TextBox Bound To Decimal - Can't Type Decimal

TextBox Bound To Decimal - Can't Type Decimal

Scheduled Pinned Locked Moved WPF
wpfhelpcsharpwcfcom
9 Posts 5 Posters 21 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I have a TextBox bound to a decimal. I'm using Clifford Nelson's [[^] Number Only Behaviour for WPF](https://www.codeproject.com/Tips/1035207/Number-Only-Behavior-for-WPF?msg=5851480#xx5851480xx). I added a DP to toggle allowing decimals called AllowDecimals, but I've found a problem, andit's NOT with Clifford's code. And it only happens when BOUND to a property. First, here's the OnTextInput

    private static void OnTextInput(object sender, TextCompositionEventArgs e)
    {
    bool allowDecimals = GetAllowDecimals((Control)sender);

    if (allowDecimals && e.Text.Any(c => c.Equals('.')))
    {
    	// When I type a decimal point, it comes here, but no decimal point appears in the textbox
    }
    else
    {
    	if (e.Text.Any(c => !char.IsDigit(c)))
    	{
    		e.Handled = true;
    	}
    }
    

    }

    As you can see by the comment, if I turn on AllowDecimals and type a '.', the code hits where it should, but I don't see it in the TextBox. If I type some digits THEN arrow over in between two digits and type a '.', then it's accepted. I beleive the problem is that the binding is trying to parse the value and somehow discards or swallows the decimal point. The WPF ToolKit has a DecimalUpDown control. I don't really want to bring in that entire library just so I can enter a decimal point. Anyone have a workaround or fix for this?

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    M Richard DeemingR 2 Replies Last reply
    0
    • K Kevin Marois

      I have a TextBox bound to a decimal. I'm using Clifford Nelson's [[^] Number Only Behaviour for WPF](https://www.codeproject.com/Tips/1035207/Number-Only-Behavior-for-WPF?msg=5851480#xx5851480xx). I added a DP to toggle allowing decimals called AllowDecimals, but I've found a problem, andit's NOT with Clifford's code. And it only happens when BOUND to a property. First, here's the OnTextInput

      private static void OnTextInput(object sender, TextCompositionEventArgs e)
      {
      bool allowDecimals = GetAllowDecimals((Control)sender);

      if (allowDecimals && e.Text.Any(c => c.Equals('.')))
      {
      	// When I type a decimal point, it comes here, but no decimal point appears in the textbox
      }
      else
      {
      	if (e.Text.Any(c => !char.IsDigit(c)))
      	{
      		e.Handled = true;
      	}
      }
      

      }

      As you can see by the comment, if I turn on AllowDecimals and type a '.', the code hits where it should, but I don't see it in the TextBox. If I type some digits THEN arrow over in between two digits and type a '.', then it's accepted. I beleive the problem is that the binding is trying to parse the value and somehow discards or swallows the decimal point. The WPF ToolKit has a DecimalUpDown control. I don't really want to bring in that entire library just so I can enter a decimal point. Anyone have a workaround or fix for this?

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I assume there is a reason why you are not using the numericupdown control and removing the U/D arrows. I would think changing the style from decimal to integer should be possible.

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      K S 2 Replies Last reply
      0
      • M Mycroft Holmes

        I assume there is a reason why you are not using the numericupdown control and removing the U/D arrows. I would think changing the style from decimal to integer should be possible.

        Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        I already stated why

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        • K Kevin Marois

          I have a TextBox bound to a decimal. I'm using Clifford Nelson's [[^] Number Only Behaviour for WPF](https://www.codeproject.com/Tips/1035207/Number-Only-Behavior-for-WPF?msg=5851480#xx5851480xx). I added a DP to toggle allowing decimals called AllowDecimals, but I've found a problem, andit's NOT with Clifford's code. And it only happens when BOUND to a property. First, here's the OnTextInput

          private static void OnTextInput(object sender, TextCompositionEventArgs e)
          {
          bool allowDecimals = GetAllowDecimals((Control)sender);

          if (allowDecimals && e.Text.Any(c => c.Equals('.')))
          {
          	// When I type a decimal point, it comes here, but no decimal point appears in the textbox
          }
          else
          {
          	if (e.Text.Any(c => !char.IsDigit(c)))
          	{
          		e.Handled = true;
          	}
          }
          

          }

          As you can see by the comment, if I turn on AllowDecimals and type a '.', the code hits where it should, but I don't see it in the TextBox. If I type some digits THEN arrow over in between two digits and type a '.', then it's accepted. I beleive the problem is that the binding is trying to parse the value and somehow discards or swallows the decimal point. The WPF ToolKit has a DecimalUpDown control. I don't really want to bring in that entire library just so I can enter a decimal point. Anyone have a workaround or fix for this?

          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

          Richard DeemingR Online
          Richard DeemingR Online
          Richard Deeming
          wrote on last edited by
          #4

          Is this related to the UpdateSourceTrigger again? Format Percentage - WPF Discussion Boards[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • M Mycroft Holmes

            I assume there is a reason why you are not using the numericupdown control and removing the U/D arrows. I would think changing the style from decimal to integer should be possible.

            Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #5

            WPFToolkit is like 1.5Mb I too try to trim my application of dead weight... It matters not much for business application, but end user application do benefit from small download files, I reckon...

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            M L 2 Replies Last reply
            0
            • S Super Lloyd

              WPFToolkit is like 1.5Mb I too try to trim my application of dead weight... It matters not much for business application, but end user application do benefit from small download files, I reckon...

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Super Lloyd wrote:

              business application

              Yeah this is where I lived :-O

              Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

              1 Reply Last reply
              0
              • S Super Lloyd

                WPFToolkit is like 1.5Mb I too try to trim my application of dead weight... It matters not much for business application, but end user application do benefit from small download files, I reckon...

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                As end users we download several Gb for Warcraft. 1.5 Mb was noticable in the dial up era; but these days your average webpage pulls in more. Also, you're using a dot as a decimal-separator. The system may be set to use a comma.

                Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                S 1 Reply Last reply
                0
                • L Lost User

                  As end users we download several Gb for Warcraft. 1.5 Mb was noticable in the dial up era; but these days your average webpage pulls in more. Also, you're using a dot as a decimal-separator. The system may be set to use a comma.

                  Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #8

                  Eddy Vluggen wrote:

                  Also, you're using a dot as a decimal-separator. The system may be set to use a comma.

                  Did you reply to the wrong person?! :O

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  L 1 Reply Last reply
                  0
                  • S Super Lloyd

                    Eddy Vluggen wrote:

                    Also, you're using a dot as a decimal-separator. The system may be set to use a comma.

                    Did you reply to the wrong person?! :O

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Whehe, I did. ..but I'm not gonna rectify either :D

                    Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups