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()