Merged PR 1515518: Ignore the Unloaded event in CompositionImage if Parent != null

Ignore the Unloaded event in CompositionImage if Parent != null.  This filters out spurious events that we receive which were causing us to prematurely dispose our surface and visuals in this control.

Related work items: #16158865, #16159585
This commit is contained in:
Scott Moore 2018-03-04 02:38:19 +00:00
Родитель 40a5569df5
Коммит 1f5b005eb6
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -221,6 +221,18 @@ namespace SamplesCommon
private void CompImage_Unloaded(object sender, RoutedEventArgs e)
{
// The Unloaded event can be fired asynchronously, and can occur spuriously, while we are still connected into the tree.
// In that case, we don't want to unload our surface and visual because this will result in the displayed image
// not being displayed. Since we don't actually reparent this control in any samples, we can detect the Unloaded event we
// actually care about by checking our Parent for null - it will be null when the UI tree is being torn down, at which point
// it is appropriate to actually free our resources.
if (Parent != null)
{
return;
}
_unloaded = true;
ReleaseSurface();