Browse files

Merged PR 1515518: Ignore the Unloaded event in CompositionImage if P…

…arent != 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
  • Loading branch information...
scott-moore-ms committed Mar 4, 2018
1 parent 40a5569 commit 1f5b005eb632e872f99fa93813d384a71c2cb963
Showing with 12 additions and 0 deletions.
  1. +12 −0 SamplesCommon/SamplesCommon/CompositionImage.cs
@@ -221,6 +221,18 @@ private void CompImage_Loading(FrameworkElement sender, object args)
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)
_unloaded = true;

0 comments on commit 1f5b005

Please sign in to comment.