public virtual void OnNavigatedTo(NavigationArgs e, string parametersKey) { // Load parameters only the first time you arrive on the view if (e.Mode == NavigationArgs.NavigationMode.New) { NavigationParameters = NavigationService.GetParameters(parametersKey); if (NavigationParameters != null) { //Process auto navigation parameters property foreach (PropertyInfo property in GetType().GetRuntimeProperties().Where(x => x.GetCustomAttribute <NavigationParameterAttribute>(true) != null)) { NavigationParameterAttribute attribute = property.GetCustomAttribute <NavigationParameterAttribute>(true); string parameterName = attribute.Name ?? property.Name; if (attribute.Mode == NavigationParameterMode.Required && !NavigationParameters.Has(parameterName)) { throw new ArgumentOutOfRangeException(string.Format("Missing required navigation parameter {0}", parameterName)); } if (NavigationParameters.Has(parameterName)) { object keyValue = NavigationParameters.Get <object>(parameterName); property.SetValue(this, keyValue); } } } } }
public virtual void Initialize(Dictionary <string, object> navigationParameters) { _navigationParameters = navigationParameters; if (_navigationParameters != null) { //Process auto navigation parameters property foreach (PropertyInfo property in GetType().GetRuntimeProperties().Where(x => x.GetCustomAttribute <NavigationParameterAttribute>(true) != null)) { NavigationParameterAttribute attribute = property.GetCustomAttribute <NavigationParameterAttribute>(true); string parameterName = attribute.Name ?? property.Name; object keyValue = GetNavigationParameter <object>(parameterName); property.SetValue(this, keyValue); } } }