Skip to content

Commit

Permalink
Renaming and documentation concerning property events of IPageContain…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
stephanpalmer committed Jun 18, 2021
1 parent 3e61bc7 commit ad9165a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions QuickTest/UserNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ void HandleFlyoutPagePropertyChanged(object sender, PropertyChangedEventArgs e)
HandlePageAppearing(page);
}

void HandlePageContainerPropertyChanging(object sender, Xamarin.Forms.PropertyChangingEventArgs e)
// To be used with Page classes implementing IPageContainer.
// Luckily, even though IPageContainer does not include the property changing event,
// all classes implementing IPageContainer do send this event for CurrentPage.
void HandleContainerPagePropertyChanging(object sender, Xamarin.Forms.PropertyChangingEventArgs e)
{
var pageContainer = sender as IPageContainer<Page>;
if (e.PropertyName != nameof(pageContainer.CurrentPage))
return;
HandlePageDisappearing(pageContainer.CurrentPage);
}

void HandlePageContainerPropertyChanged(object sender, PropertyChangedEventArgs e)
// To be used with Page classes implementing IPageContainer.
// Luckily, even though IPageContainer does not include the property changed event,
// all classes implementing IPageContainer do send this event for CurrentPage.
void HandleContainerPagePropertyChanged(object sender, PropertyChangedEventArgs e)
{
var pageContainer = sender as IPageContainer<Page>;
if (e.PropertyName != nameof(pageContainer.CurrentPage))
Expand Down Expand Up @@ -140,8 +146,8 @@ void SubscribeToPageEvents(Page page)
}

if (page is IPageContainer<Page> pageContainer) {
page.PropertyChanging += HandlePageContainerPropertyChanging;
page.PropertyChanged += HandlePageContainerPropertyChanged;
page.PropertyChanging += HandleContainerPagePropertyChanging;
page.PropertyChanged += HandleContainerPagePropertyChanged;
SubscribeToPageEvents(pageContainer.CurrentPage);
}
}
Expand All @@ -156,8 +162,8 @@ void UnsubscribeFromPageEvents(Page page)
}

if (page is IPageContainer<Page> pageContainer) {
page.PropertyChanging -= HandlePageContainerPropertyChanging;
page.PropertyChanged -= HandlePageContainerPropertyChanged;
page.PropertyChanging -= HandleContainerPagePropertyChanging;
page.PropertyChanged -= HandleContainerPagePropertyChanged;
UnsubscribeFromPageEvents(pageContainer.CurrentPage);
}
}
Expand Down

0 comments on commit ad9165a

Please sign in to comment.