Fix 7 critical bugs in NumericUpDown and DateTimePicker#4565
Open
Thuram2003 wants to merge 2 commits intoMahApps:developfrom
Open
Fix 7 critical bugs in NumericUpDown and DateTimePicker#4565Thuram2003 wants to merge 2 commits intoMahApps:developfrom
Thuram2003 wants to merge 2 commits intoMahApps:developfrom
Conversation
This commit addresses 7 critical issues identified through comprehensive code analysis: 1. NumericUpDown keyboard input blocking (MahApps#4561) - Users can now type intermediate values (e.g., "5" when minimum is 50) - Coercion happens on focus lost instead of blocking input - Improves user experience significantly 2. DateTimePicker DateTimeKind inconsistency (MahApps#4551) - All DateTime values now consistently return DateTimeKind.Local - Eliminates timezone-related bugs and data inconsistencies - Uses DateTime.SpecifyKind() for consistency 3. Double ValueChanged event firing - Removed duplicate OnValueChanged() call in ChangeValueFromTextInput - Event now fires exactly once per value change - Improves performance and prevents duplicate processing 4. Dangerous async void method - Converted SimulateDecimalPointKeyPress from async void to synchronous - Eliminates risk of unhandled exceptions crashing the application - Removed unnecessary await Task.FromResult(true) 5. Integer overflow in hexadecimal formatting - Added validation before casting double to int in TryFormatHexadecimal - Prevents OverflowException when value > int.MaxValue - Properly rejects decimal values in hex mode 6. Event handler memory leaks in OnApplyTemplate - Added cleanup code to remove old handlers before adding new ones - Converted lambda expressions to named methods for proper removal - Prevents memory leaks when templates change (theme/style switches) 7. Unnecessary double coercion in SetValueTo - Removed manual CoerceValue() call - Dependency property system already handles coercion automatically - Improves performance by eliminating redundant processing All fixes: - Compile successfully across all target frameworks (net462, net6.0-windows, net8.0-windows) - Include no breaking changes to the public API - Are thoroughly documented with before/after code examples - Have comprehensive testing guidelines Fixes MahApps#4561, MahApps#4551
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes multiple critical issues in NumericUpDown and DateTimePicker controls in MahApps.Metro, improving stability, usability, and performance.
🔧 Key Fixes
Fixed keyboard input blocking in NumericUpDown
Fixed inconsistent DateTimeKind in DateTimePicker
Prevented duplicate ValueChanged event firing
Replaced unsafe async void method to improve stability
Fixed potential integer overflow in hexadecimal formatting
Improved event handler cleanup to prevent memory leaks
Removed unnecessary double value coercion for better performance
🎯 Impact
Better user input experience (smoother typing)
More consistent and reliable date handling
Improved performance and memory safety
Reduced risk of crashes and unexpected behavior
🧪 Testing
Verified compilation across target frameworks (.NET Framework & .NET 6/8)
Manually tested all affected controls
No breaking changes introduced
📌 Notes
All changes are backward compatible and focused on improving internal control behavior without affecting public APIs.