Skip to content

Commit 62b4611

Browse files
committed
Added extension method for GoToState
1 parent 7dad754 commit 62b4611

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Microsoft.UI.Xaml;
2+
3+
internal static class VisualStateHelpers
4+
{
5+
public static bool GoToState(this Control control, string stateName, bool useAnimation = true) =>
6+
VisualStateManager.GoToState(control, stateName, useAnimation);
7+
}

src/Codebreaker.Uno/CodebreakerUno/Views/Components/GameResultDisplay.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public sealed partial class GameResultDisplay : UserControl
88
public GameResultDisplay()
99
{
1010
InitializeComponent();
11-
VisualStateManager.GoToState(this, "Default", false);
11+
this.GoToState("Default", false);
1212
}
1313

1414
public GamePageViewModel ViewModel
@@ -37,6 +37,6 @@ private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs
3737
GameMode.Lost => "Lost",
3838
_ => "Default"
3939
};
40-
VisualStateManager.GoToState(this, stateName, true);
40+
this.GoToState(stateName);
4141
}
4242
}

src/Codebreaker.Uno/CodebreakerUno/Views/Pages/GamePage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public GamePage()
1818
WeakReferenceMessenger.Default.Register(this);
1919
WeakReferenceMessenger.Default.UnregisterAllOnUnloaded(this);
2020
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
21-
VisualStateManager.GoToState(this, "Start", false);
21+
this.GoToState("Start", false);
2222
}
2323

2424
public GamePageViewModel ViewModel { get; }
@@ -61,6 +61,6 @@ private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.Pro
6161
GameMode.Won or GameMode.Lost => "Finished",
6262
_ => "Start",
6363
};
64-
VisualStateManager.GoToState(this, stateName, true);
64+
this.GoToState(stateName);
6565
}
6666
}

0 commit comments

Comments
 (0)