diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs index 5f71b2ecd9..7c17b125d6 100644 --- a/samples/ControlCatalog/MainView.xaml.cs +++ b/samples/ControlCatalog/MainView.xaml.cs @@ -60,8 +60,8 @@ namespace ControlCatalog var decorations = this.Find("Decorations"); decorations.SelectionChanged += (sender, e) => { - Window window = (Window)VisualRoot; - window.SystemDecorations = (SystemDecorations)decorations.SelectedIndex; + if (VisualRoot is Window window) + window.SystemDecorations = (SystemDecorations)decorations.SelectedIndex; }; } @@ -69,7 +69,8 @@ namespace ControlCatalog { base.OnAttachedToVisualTree(e); var decorations = this.Find("Decorations"); - decorations.SelectedIndex = (int)((Window)VisualRoot).SystemDecorations; + if (VisualRoot is Window window) + decorations.SelectedIndex = (int)window.SystemDecorations; } } } diff --git a/src/Avalonia.Controls/Remote/RemoteWidget.cs b/src/Avalonia.Controls/Remote/RemoteWidget.cs index c7a1a24c25..fabb38f87d 100644 --- a/src/Avalonia.Controls/Remote/RemoteWidget.cs +++ b/src/Avalonia.Controls/Remote/RemoteWidget.cs @@ -75,7 +75,11 @@ namespace Avalonia.Controls.Remote var fmt = (PixelFormat) _lastFrame.Format; if (_bitmap == null || _bitmap.PixelSize.Width != _lastFrame.Width || _bitmap.PixelSize.Height != _lastFrame.Height) - _bitmap = new WriteableBitmap(new PixelSize(_lastFrame.Width, _lastFrame.Height), new Vector(96, 96), fmt); + { + _bitmap?.Dispose(); + _bitmap = new WriteableBitmap(new PixelSize(_lastFrame.Width, _lastFrame.Height), + new Vector(96, 96), fmt); + } using (var l = _bitmap.Lock()) { var lineLen = (fmt == PixelFormat.Rgb565 ? 2 : 4) * _lastFrame.Width;