Skip to content

Commit 0ff7d5d

Browse files
authored
TextBoxLineCountBehavior: Fixed issue with UpdateAttachedProperties being called after detached causing NullReferenceException (#3769)
1 parent 32e2584 commit 0ff7d5d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ public class TextBoxLineCountBehavior : Behavior<TextBox>
1212

1313
private void UpdateAttachedProperties()
1414
{
15-
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount);
16-
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1);
15+
if (AssociatedObject != null)
16+
{
17+
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount);
18+
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1);
19+
}
1720
}
1821

1922
protected override void OnAttached()

0 commit comments

Comments
 (0)