TextBox Bound To Decimal - Can't Type Decimal
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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!
-
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!
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
-
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!
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.
-
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.
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!
-
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!