Content update - Safe constructor patterns for DependencyObjects (user story 1878471) #1254
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.
@adegeo, this PR is ready for your review.
The snippets and safe constructor patterns have been updated because:
In the first existing snippet,
MyClassis a derived class that implements the virtualOnPropertyChangedmethod.MyClassalso declares the uninitialized variable_myList(which doesn't exist in the base class). The first snippet demonstrates how a derived class method (OnPropertyChanged), which overrides a base class virtual method, can access_myListbefore it's initialized. However, this snippet is an incomplete example, because:The two other existing snippets convey that member initialization for callbacks should happen in the base class parameterless constructor. However, that approach doesn't solve the problem in the first snippet because
_myListdoesn't exist in the base class and so can't be initialized from there. Instead, that problem should be addressed in the derived class. Another recommendation was "make sure that callbacks use only other dependency properties", which isn't appropriate for many dependency property scenarios.Internal preview link