Skip to content

Commit f20c9d8

Browse files
committed
Created extension method for GoToState
1 parent dc075a5 commit f20c9d8

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

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

src/Codebreaker.MAUI/Views/Components/GameResultDisplay.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public GameResultDisplay()
88
{
99
InitializeComponent();
1010
Loaded += OnLoaded;
11-
GoToState("Default");
11+
this.GoToState("Default");
1212
}
1313

1414
public GamePageViewModel ViewModel => (GamePageViewModel)BindingContext;
@@ -29,9 +29,6 @@ private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs
2929
GameMode.Lost => "Lost",
3030
_ => "Default"
3131
};
32-
GoToState(stateName);
32+
this.GoToState(stateName);
3333
}
34-
35-
private void GoToState(string stateName) =>
36-
VisualStateManager.GoToState(this, stateName);
3734
}

src/Codebreaker.MAUI/Views/Pages/GamePage.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public GamePage(GamePageViewModel viewModel, INavigationService navigationServic
1414
BindingContext = viewModel;
1515
WeakReferenceMessenger.Default.RegisterAll(this);
1616
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
17-
GoToState("Start");
17+
this.GoToState("Start");
1818
}
1919

2020
public GamePageViewModel ViewModel { get; }
@@ -44,12 +44,9 @@ private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.Pro
4444
GameMode.Won or GameMode.Lost => "Finished",
4545
_ => "Start",
4646
};
47-
GoToState(stateName);
47+
this.GoToState(stateName);
4848
}
4949

50-
private void GoToState(string stateName) =>
51-
VisualStateManager.GoToState(ContentWrapper, stateName);
52-
5350
private async void Button_Clicked(object sender, EventArgs e)
5451
{
5552
await _navigationService.NavigateToAsync("TestPage");

0 commit comments

Comments
 (0)