Skip to content

Instantly share code, notes, and snippets.

@rohits79
Created June 15, 2016 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohits79/ebe5684df53038a99ef6595c41cc4366 to your computer and use it in GitHub Desktop.
Save rohits79/ebe5684df53038a99ef6595c41cc4366 to your computer and use it in GitHub Desktop.
public object LoadContent(IRegion region, NavigationContext navigationContext)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
if (navigationContext == null)
throw new ArgumentNullException(nameof(navigationContext));
string candidateTargetContract = this.GetContractFromNavigationContext(navigationContext);
var candidates = this.GetCandidatesFromRegion(region, candidateTargetContract);
var acceptingCandidates =
candidates.Where(
v =>
{
var navigationAware = v as INavigationAware;
if (navigationAware != null && !navigationAware.IsNavigationTarget(navigationContext))
{
return false;
}
var frameworkElement = v as FrameworkElement;
if (frameworkElement == null)
{
return true;
}
navigationAware = frameworkElement.DataContext as INavigationAware;
return navigationAware == null || navigationAware.IsNavigationTarget(navigationContext);
});
var view = acceptingCandidates.FirstOrDefault();
if (view != null)
{
return view;
}
view = this.CreateNewRegionItem(candidateTargetContract);
region.Add(view);
return view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment