From 1c5621ead830801715b86a486ab551d26f53327f Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 3 Oct 2024 23:17:00 -0400 Subject: [PATCH] fix: Don't fail on disposed color changes --- .../Xaml/Controls/TextBox/TextBoxView.Android.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs index 2a1ef473c064..8069abc79a66 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs @@ -28,6 +28,7 @@ internal partial class TextBoxView : EditText, DependencyObject internal TextBox? Owner => _ownerRef?.Target as TextBox; private Action? _foregroundChanged; + private bool _isDisposed; public TextBoxView(TextBox owner) : base(ContextHelper.Current) @@ -313,10 +314,23 @@ private void OnForegroundChanged(Brush oldValue, Brush newValue) void ApplyColor() { + if (_isDisposed) + { + // Binding changes may happen after the + // underlying control has been disposed + return; + } + SetTextColor(scb.Color); SetCursorColor(scb.Color); } } } + + protected override void Dispose(bool disposing) + { + _isDisposed = true; + base.Dispose(disposing); + } } }