Skip to content

Commit

Permalink
fix: XamlRoot may be null when the SKXamlCanvas is unloaded (#2854) (#…
Browse files Browse the repository at this point in the history
…2884)

* fix: XamlRoot may be null when the SKXamlCanvas is unloaded

* chore: Adjust more xamlroot uses

---------

Co-authored-by: Matthew Leibowitz <[email protected]>
(cherry picked from commit 8e7a51d)

Co-authored-by: Jérôme Laban <[email protected]>
  • Loading branch information
github-actions[bot] and jeromelaban authored Jun 18, 2024
1 parent d3448f5 commit a65d20f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyCh
private void OnXamlRootChanged(XamlRoot xamlRoot = null, XamlRootChangedEventArgs e = null)
{
var root = xamlRoot ?? XamlRoot;
Dpi = root.RasterizationScale;
Dpi = root?.RasterizationScale ?? 1.0;
Invalidate();
}
#else
Expand Down Expand Up @@ -141,7 +141,10 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
return;

#if WINDOWS
XamlRoot.Changed -= OnXamlRootChanged;
if(XamlRoot != null)
{
XamlRoot.Changed -= OnXamlRootChanged;
}
#else
var display = DisplayInformation.GetForCurrentView();
display.DpiChanged -= OnDpiChanged;
Expand Down

0 comments on commit a65d20f

Please sign in to comment.