Skip to content

Commit

Permalink
Fix: Prevent Toggled triggering on initial load (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
IeuanWalker committed Apr 14, 2023
1 parent c7074d3 commit 1df7a93
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Scr/Switch/CustomSwitch.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public partial class CustomSwitch : SwitchView
#region Properties

// General properties
private SwitchStateEnum CurrentState { get; set; }
SwitchStateEnum CurrentState { get; set; }
bool HasLoaded { get; set; }

double _xRef;

Expand Down Expand Up @@ -201,7 +202,11 @@ public CustomSwitch()
{
GoToLeft(100);
}
HasLoaded = true;
};


}

protected override void IsToggledChanged()
Expand All @@ -215,7 +220,10 @@ protected override void IsToggledChanged()
GoToLeft();
}

InvokeToggled();
if (HasLoaded)
{
InvokeToggled();
}

base.IsToggledChanged();
}
Expand All @@ -225,6 +233,7 @@ void GoToLeft(double percentage = 0.0)
if (Math.Abs(KnobFrame.TranslationX + _xRef) > 0.0)
{
this.AbortAnimation("SwitchAnimation");

new Animation
{
{0, 1, new Animation(v => KnobFrame.TranslationX = v, KnobFrame.TranslationX, -_xRef)},
Expand Down Expand Up @@ -252,7 +261,6 @@ void GoToRight(double percentage = 0.0)
{
this.AbortAnimation("SwitchAnimation");

IsToggled = true;
new Animation
{
{0, 1, new Animation(v => KnobFrame.TranslationX = v, KnobFrame.TranslationX, _xRef)},
Expand All @@ -261,6 +269,7 @@ void GoToRight(double percentage = 0.0)
{
this.AbortAnimation("SwitchAnimation");
CurrentState = SwitchStateEnum.Right;
IsToggled = true;
SendSwitchPanUpdatedEventArgs(PanStatusEnum.Completed);
});
}
Expand Down

0 comments on commit 1df7a93

Please sign in to comment.