Skip to content

Commit

Permalink
Update CustomSwitch.xaml.cs
Browse files Browse the repository at this point in the history
I met an exception when using a Style dictionary to style CustomSwitchs, with KnobFrame and BackgroundFrame being null when SizeRequestChanged is called for the first time. Adding HasLoaded in the check at the beginning of the method seems to fix this issue.
  • Loading branch information
gchapeaux authored Dec 10, 2024
1 parent 2aa3044 commit 48c9473
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Scr/Switch/CustomSwitch.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected override void OnSizeAllocated(double width, double height)

static void SizeRequestChanged(BindableObject bindable, object oldValue, object newValue)
{
if(bindable is not CustomSwitch view)
if(bindable is not CustomSwitch view || !view.HasLoaded)
{
return;
}
Expand Down Expand Up @@ -413,4 +413,4 @@ void SetBaseWidthRequest(double widthRequest)
{
base.WidthRequest = widthRequest;
}
}
}

0 comments on commit 48c9473

Please sign in to comment.