Skip to content

Commit

Permalink
Update DisplayAlert method calls to use first window's page
Browse files Browse the repository at this point in the history
Updated the `DisplayAlert` method calls in `Switch_OnToggled`
and `Toggled` methods across several files to use
`Application.Current!.Windows[0].Page!` instead of
`Application.Current!.MainPage!`. This change ensures alerts
are displayed on the first window's page, accommodating
scenarios with multiple windows or when the main page is not
active. Affected files: `CustomSwitchPage.xaml.cs`,
`PanGestureTestPage.xaml.cs`, `SwitchViewPage.xaml.cs`,
and `SwitchViewModel.cs`.
  • Loading branch information
IeuanWalker committed Nov 19, 2024
1 parent 5a47f85 commit 7b98a33
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Demo/App/Pages/CustomSwitchPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async void Switch_OnToggled(object sender, ToggledEventArgs e)
{
if (_viewModel.EnableEvents)
{
await Application.Current!.MainPage!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
await Application.Current!.Windows[0].Page!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion Demo/App/Pages/PanGestureTestPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ static void CustomSwitch_SwitchPanUpdate(CustomSwitch customSwitch, SwitchPanUpd

async void Switch_OnToggled(object sender, ToggledEventArgs e)
{
await Application.Current!.MainPage!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
await Application.Current!.Windows[0].Page!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
}
}
2 changes: 1 addition & 1 deletion Demo/App/Pages/SwitchViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async void Switch_OnToggled(object sender, ToggledEventArgs e)
{
if (_viewModel.EnableEvents)
{
await Application.Current!.MainPage!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
await Application.Current!.Windows[0].Page!.DisplayAlert("Switch toggled (Event)", $"New value: {e.Value}", "OK").ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion Demo/App/ViewModels/SwitchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public async Task Toggled(bool value)
{
if (EnableCommands)
{
await Application.Current!.MainPage!.DisplayAlert("Switch toggled (Command)", $"New value: {value}", "OK").ConfigureAwait(false);
await Application.Current!.Windows[0].Page!.DisplayAlert("Switch toggled (Command)", $"New value: {value}", "OK").ConfigureAwait(false);
}
}
}

0 comments on commit 7b98a33

Please sign in to comment.