fix: XamlRoot may be null when the SKXamlCanvas is unloaded (#2854)

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

* chore: Adjust more xamlroot uses

---------

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
This commit is contained in:
Jérôme Laban 2024-06-03 10:22:23 -04:00 коммит произвёл GitHub
Родитель 258a6f62bd
Коммит 8e7a51dc04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 5 добавлений и 2 удалений

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

@ -101,7 +101,7 @@ namespace SkiaSharp.Views.UWP
private void OnXamlRootChanged(XamlRoot xamlRoot = null, XamlRootChangedEventArgs e = null) private void OnXamlRootChanged(XamlRoot xamlRoot = null, XamlRootChangedEventArgs e = null)
{ {
var root = xamlRoot ?? XamlRoot; var root = xamlRoot ?? XamlRoot;
Dpi = root.RasterizationScale; Dpi = root?.RasterizationScale ?? 1.0;
Invalidate(); Invalidate();
} }
#else #else
@ -141,7 +141,10 @@ namespace SkiaSharp.Views.UWP
return; return;
#if WINDOWS #if WINDOWS
XamlRoot.Changed -= OnXamlRootChanged; if(XamlRoot != null)
{
XamlRoot.Changed -= OnXamlRootChanged;
}
#else #else
var display = DisplayInformation.GetForCurrentView(); var display = DisplayInformation.GetForCurrentView();
display.DpiChanged -= OnDpiChanged; display.DpiChanged -= OnDpiChanged;