-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix issue where setting StaggeredLayout.ColumnWidth to NaN would cause an exception #4064
Conversation
Thanks winston-de for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
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.
Thanks, @winston-de for the quick fix! Looks good and does not seem to be crashing anymore 🚀
May I ask how you encountered this, was the value generated from something else or did you want a "use available with" option? |
@RosarioPulella I encountered this error when experimenting with different values for the column width. The reason I chose the use available width behavior was because that's how the staggered panel control handles NaN for the column width. If you'd like, I can change it, as the main goal of this PR is just to prevent the crash from occurring. |
So I tried the sample code (more or less) in its own project and added a button to update the I think its important that Also the sample app should not freeze if a sample throws an exception. The sample app needs to be able to isolate it's self from issues in samples, that is a separate issue that needs to be investigated. |
At first I was thing that maybe we should just throw a more relevant exception in |
@skendrot thoughts on this change? |
One other thing to point out, that is if the intent is to 'clear' the default value using |
From WPF, for controls that derive from FrameworkElement, NaN was implied to mean "not set". Properties such as Width and Height backed to dependency properties, where their default values were set to NaN. NaN would continue to be the values for these properties, until they were explicitly given a value. ActualWidth & ActualHeight (in this example) were more reliable values to read from. |
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.
Thanks for the background @XAML-Knight. Seems similar setup in UWP. Though the "Auto"
value will get converted to NaN
as well. Interesting that trying to type Auto
doesn't work outside of Width
/Height
.
Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredLayout/StaggeredLayout.cs
Show resolved
Hide resolved
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Fixes #4063
The exception was caused by having
NaN
the value of width initem.Element.Measure
. This PR fixes this by adding a check ifDesiredColumnWidth
isNaN
, and if so setting it instead to the available width.PR Type
Bugfix
What is the current behavior?
When
DesiredColumnWidth
isNaN
, an exception will be thrown when measuring item sizes, which causes a crash or will freeze the app.What is the new behavior?
If
DesiredColumnWidth
isNaN
, items are stretched to fit the available width.Example:
PR Checklist
Please check if your PR fulfills the following requirements:
Other information