From 3244b370a9eb8a74322a193fb6f224cfa9aaa37f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 31 May 2018 00:33:55 +0200 Subject: [PATCH] Make sure to detach static event for UWP. #429 --- .../SkiaSharp.Views.UWP/SKXamlCanvas.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs index 4311f3c4..1de76d4f 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs @@ -30,11 +30,7 @@ namespace SkiaSharp.Views.UWP SizeChanged += OnSizeChanged; Unloaded += OnUnloaded; - - // get the scale from the current display - var display = DisplayInformation.GetForCurrentView(); - OnDpiChanged(display); - display.DpiChanged += OnDpiChanged; + Loaded += OnLoaded; } public SKSize CanvasSize => bitmap == null ? SKSize.Empty : new SKSize(bitmap.PixelWidth, bitmap.PixelHeight); @@ -69,8 +65,19 @@ namespace SkiaSharp.Views.UWP Invalidate(); } + private void OnLoaded(object sender, RoutedEventArgs e) + { + var display = DisplayInformation.GetForCurrentView(); + display.DpiChanged += OnDpiChanged; + + OnDpiChanged(display); + } + private void OnUnloaded(object sender, RoutedEventArgs e) { + var display = DisplayInformation.GetForCurrentView(); + display.DpiChanged -= OnDpiChanged; + FreeBitmap(); }