Skip to content

Instantly share code, notes, and snippets.

@leemean
Created March 26, 2019 02:20
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 leemean/179804cbd2026b1e753beb774e9a495e to your computer and use it in GitHub Desktop.
Save leemean/179804cbd2026b1e753beb774e9a495e to your computer and use it in GitHub Desktop.
NavigationAware
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
namespace APS.Infrastructure.MVVM
{
/// <summary>
/// NavigationAware
/// </summary>
public abstract class NavigationAware : BaseViewModel , INavigationAware
{
private string uriQueryString;
public event EventHandler Activate;
public NavigationAware() { }
public NavigationAware(IUnityContainer unityContainer, IRegionManager regionManager)
: base(unityContainer, regionManager) { }
public bool IsNavigationTarget(NavigationContext navigationContext)
{
if(!string.IsNullOrEmpty(uriQueryString))
{
RaiseActivation();
return true;
}
return false;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
if (!String.IsNullOrEmpty(uriQueryString)
&& uriQueryString.Equals(navigationContext.Uri.OriginalString))
{
return;
}
uriQueryString = navigationContext.Uri.OriginalString;
foreach (KeyValuePair<string, object> parameter in navigationContext.Parameters)
{
if (parameter.Key.Equals("Caption"))
{
Title = parameter.Value.ToString();
continue;
}
if(parameter.Key.Equals("Key"))
{
Key = "k_" + parameter.Value.ToString();
continue;
}
}
}
private void RaiseActivation()
{
Activate?.Invoke(this, EventArgs.Empty);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment