From 0ff7d5da9788321263f47f1e6f354d96af9690e7 Mon Sep 17 00:00:00 2001 From: Joris Voermans Date: Mon, 13 Jan 2025 08:51:16 +0100 Subject: [PATCH] TextBoxLineCountBehavior: Fixed issue with UpdateAttachedProperties being called after detached causing NullReferenceException (#3769) --- .../Behaviors/TextBoxLineCountBehavior.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs b/src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs index 7940b4e1a6..582294a800 100644 --- a/src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs +++ b/src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs @@ -12,8 +12,11 @@ public class TextBoxLineCountBehavior : Behavior private void UpdateAttachedProperties() { - AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount); - AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1); + if (AssociatedObject != null) + { + AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount); + AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1); + } } protected override void OnAttached()