Skip to content

Commit 66b836b

Browse files
authored
TextBoxLineCountBehavior: Fixed NullReferenceException when used within Virtualizing DataGrid (#3871)
1 parent cf1afbc commit 66b836b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Xaml.Behaviors;
1+
using System.Windows.Threading;
2+
using Microsoft.Xaml.Behaviors;
23

34
namespace MaterialDesignThemes.Wpf.Behaviors;
45

@@ -14,8 +15,13 @@ private void UpdateAttachedProperties()
1415
{
1516
if (AssociatedObject is { } associatedObject)
1617
{
17-
associatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, associatedObject.LineCount);
18-
associatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, associatedObject.LineCount > 1);
18+
associatedObject.Dispatcher
19+
.BeginInvoke(() =>
20+
{
21+
associatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, associatedObject.LineCount);
22+
associatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, associatedObject.LineCount > 1);
23+
},
24+
DispatcherPriority.Background);
1925
}
2026
}
2127

0 commit comments

Comments
 (0)