-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ImageResizer] Fix issues with blank Width and Height controls #37373
base: main
Are you sure you want to change the base?
[ImageResizer] Fix issues with blank Width and Height controls #37373
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Failed XAML formatting |
Thanks, @crutkas , and sorry for missing that. I've corrected the namespace ordering, and everything passes locally now. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Hi @daverayment The Image Resizer UI appears as expected, and the code looks good to me. However, the settings page also needs to be updated. Could you update this part as well? |
Thank you for the review, @lei9444. I agree that it makes sense to fix the settings formatting, just so everything is consistent. There is an Do you think the capitalisation of the scaling mode needs altering, too? The line starts with a capital letter in the settings, but not in the ImageResizer UI itself. Thanks again. |
Thanks @daverayment Good catch on this one. I think we should keep them consistent. Maybe we could create another PR for the format change to keep this PR focused on the issue fix. @crutkas do you have any suggestion on this? |
I’m fine with that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
Files not reviewed (2)
- src/modules/imageresizer/ui/App.xaml: Language not supported
- src/modules/imageresizer/ui/Views/InputPage.xaml: Language not supported
Comments suppressed due to low confidence (1)
src/modules/imageresizer/ui/Views/NumberBoxValueConverter.cs:18
- The method should return an empty string for double.NaN to be consistent with ZeroToEmptyStringNumberFormatter.
value is double d && double.IsNaN(d) ? 0 : value;
Summary of the Pull Request
This fixes some related issues with the Width and Height NumberBox controls for the Custom preset. The issues were:
PR Checklist
Detailed Description of the Pull Request / Additional comments
The issue centred around the fact that emptying a NumberBox bound to a non-nullable double value will result in a data binding error because the empty control now has a null
Value
.Inputting 0 into the fields instead of clearing them completely is fine and would be reasonable as a workaround, but this does not reflect the description of the feature on the Image Resizer help page, which specifically mentions that one or the other dimension field may be left blank to take advantage of the auto-scaling functionality.
The solution is to translate empty strings to 0, but not to display 0 in the UI. This is achieved through combining a NumberFormatter and a ValueConverter:
Without the ValueConverter, the data binding step would fail because
null
is the value of a cleared NumberBox and we would be attempting to bind toResizeSize.Width
orResizeSize.Height
, which are non-nullable.There are likely some alternative methods to get around this, perhaps by using
double.NaN
instead of 0, or changing Width and Height to nullable. However, relying on the ValueConverter and NumberFormatter means that we do not need to change the underlying types, and this was seen as lower risk.I made a few changes and added comments to AutoDoubleConverter.cs. This was because I initially thought I could use it on the custom preset's Width and Height fields, before deciding to create a new Converter made specifically to resolve the issue at hand. Also, I took the opportunity to make it more defensive in terms of type handling by using pattern matching. The functionality is identical.
Validation Steps Performed
The application was manually tested both via the command line and by running directly from Visual Studio (which opens up the file picker because there is no file pre-selected).
Tested that:
Screenshots
Dimensions may be blank without validation errors:

Empty dimensions are correctly marked as auto in the presets drop-down:
