Skip to content

Commit ded833b

Browse files
Add null guards and possibly not-needed method SizeChanged() invoke
1 parent 92f0542 commit ded833b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/MaterialDesignThemes.Wpf/Behaviors/TextBoxHorizontalScrollBarBehavior.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
4646
{
4747
AssociatedObject.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
4848
_builtInScrollBar = AssociatedObject.FindChild<ScrollBar>("PART_HorizontalScrollBar");
49+
50+
AssociatedObject_SizeChanged(sender, null!); // TODO: Possibly not needed
4951
}
5052

5153
private void AssociatedObject_SizeChanged(object sender, SizeChangedEventArgs e)
5254
{
53-
if (TargetScrollBar is not { } ts) return;
55+
if (TargetScrollBar is not { } ts || _builtInScrollBar is null) return;
5456

5557
ts.ViewportSize = AssociatedObject.ViewportWidth;
5658
ts.Value = AssociatedObject.HorizontalOffset;
@@ -60,7 +62,7 @@ private void AssociatedObject_SizeChanged(object sender, SizeChangedEventArgs e)
6062

6163
private void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArgs e)
6264
{
63-
if (TargetScrollBar is not { } ts) return;
65+
if (TargetScrollBar is not { } ts || _builtInScrollBar is null) return;
6466

6567
ts.Value = AssociatedObject.HorizontalOffset;
6668
ts.Maximum = _builtInScrollBar!.Maximum;

0 commit comments

Comments
 (0)