Skip to content

Commit

Permalink
Merge branch 'main' into feature/pomianowski/update-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski authored Aug 11, 2024
2 parents fbde0d6 + d27947e commit c4497fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/Expander/Expander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<!-- Top level controls always visible -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,42 @@ private void ApplyTransitionEffectToNavigatedPage(object content)

private static void NotifyContentAboutNavigatingTo(object content)
{
switch (content)
{
case INavigationAware navigationAwareNavigationContent:
_ = Task.Run(navigationAwareNavigationContent.OnNavigatedToAsync).ConfigureAwait(false);
break;
case INavigableView<object> { ViewModel: INavigationAware navigationAwareNavigableViewViewModel }:
_ = Task.Run(navigationAwareNavigableViewViewModel.OnNavigatedToAsync).ConfigureAwait(false);
break;
case FrameworkElement { DataContext: INavigationAware navigationAwareCurrentContent }:
_ = Task.Run(navigationAwareCurrentContent.OnNavigatedToAsync).ConfigureAwait(false);
break;
}
NotifyContentAboutNavigating(content, navigationAware => navigationAware.OnNavigatedToAsync());
}

private static void NotifyContentAboutNavigatingFrom(object content)
{
NotifyContentAboutNavigating(content, navigationAware => navigationAware.OnNavigatedFromAsync());
}

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"ReSharper",
"SuspiciousTypeConversion.Global",
Justification = "The library user might make a class inherit from both FrameworkElement and INavigationAware at the same time."
)]
private static void NotifyContentAboutNavigating(object content, Func<INavigationAware, Task> function)
{
switch (content)
{
// The order in which the OnNavigatedToAsync/OnNavigatedFromAsync methods of View and ViewModel are called
// is not guaranteed
case INavigationAware navigationAwareNavigationContent:
_ = Task.Run(navigationAwareNavigationContent.OnNavigatedFromAsync).ConfigureAwait(false);
_ = Task.Run(() => function(navigationAwareNavigationContent)).ConfigureAwait(false);
if (
navigationAwareNavigationContent
is FrameworkElement { DataContext: INavigationAware viewModel }
&& !ReferenceEquals(viewModel, navigationAwareNavigationContent)
)
{
_ = Task.Run(() => function(viewModel)).ConfigureAwait(false);
}

break;
case INavigableView<object> { ViewModel: INavigationAware navigationAwareNavigableViewViewModel }:
_ = Task.Run(navigationAwareNavigableViewViewModel.OnNavigatedFromAsync)
.ConfigureAwait(false);
_ = Task.Run(() => function(navigationAwareNavigableViewViewModel)).ConfigureAwait(false);
break;
case FrameworkElement { DataContext: INavigationAware navigationAwareCurrentContent }:
_ = Task.Run(navigationAwareCurrentContent.OnNavigatedFromAsync).ConfigureAwait(false);
_ = Task.Run(() => function(navigationAwareCurrentContent)).ConfigureAwait(false);
break;
}
}
Expand Down

0 comments on commit c4497fb

Please sign in to comment.