-
Notifications
You must be signed in to change notification settings - Fork 708
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 with setting SelectedItem on TreeView would crash application #3136
Fix issue with setting SelectedItem on TreeView would crash application #3136
Conversation
@@ -264,7 +264,7 @@ void TreeView::OnPropertyChanged(const winrt::DependencyPropertyChangedEventArgs | |||
{ | |||
|
|||
const auto items = SelectedItems(); | |||
const auto selected = items.Size() > 0 ? items.GetAt(0) : nullptr; | |||
const auto selected = (items != nullptr && items.Size() > 0) ? items.GetAt(0) : nullptr; |
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.
items != nullptr [](start = 31, length = 16)
Under what circumstances is this null?
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.
It seems that SelectedItems returns null when TreeView can't resolve it's listcontrol.
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.
and what causes that to happen?
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.
SelectedItems returns null if the internal listview can't be found or the listviews ListViewModel can't be found. So in #3129, we probably crashed due to the binding resolving before the template was applied leaving us in a state where we did not have a listview or selectionmodel.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@chingucoding can you merge master to pick up the CI build fix that just went in? |
@StephenLPeters This and all other opens PR I created are up to date now. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Any ETA on when this will be available? |
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.
@sis2004 I just merged this into the repository so it will be included in the next versions. I'd guess there will be a prerelease version made during September, when it is the bot will post on the original issue that it was included in the package. |
@StephenLPeters thanks, I'll keep an eye out for it. |
Description
The issue is that
SelectedItem
might be null in some cases which we didn't anticipate. Added a nullcheck to the selecteditems to guard against this.The brackets were added to improve readability.
Motivation and Context
Fixes #3129
How Has This Been Tested?
Add new API test.
Screenshots (if appropriate):