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
* fix: XamlRoot may be null when the SKXamlCanvas is unloaded

* chore: Adjust more xamlroot uses

---------

Co-authored-by: Matthew Leibowitz <[email protected]>
  • Loading branch information
jeromelaban and mattleibow authored Jun 3, 2024
1 parent 258a6f6 commit 8e7a51d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/SkiaSharp.Views/SkiaSharp.Views.WinUI/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 8e7a51d

Please sign in to comment.