public static object GetDataContext(NavigationContext navContext) { string id; if (navContext != null && navContext.QueryString != null && navContext.QueryString.TryGetValue(ViewModelIdArgumentName, out id)) { return(ViewModelsRegistry.GetById(id)); } return(null); }
public void Navigate <T>(T viewModel) { var page = ViewsMap[viewModel.GetType()]; var frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame == null) { throw new InvalidOperationException("Frame is null"); } if (frame.Content is FrameworkElement) { var dc = ((FrameworkElement)frame.Content).DataContext; if (dc != null && dc.Equals(viewModel)) { return; } } bool isRootPage = RootViewModels.Contains(viewModel.GetType()); if (isRootPage) { while (frame.BackStack.Any()) { var entry = frame.RemoveBackEntry(); //TODO: log entry.Source; } } bool navigationResult = frame.Navigate(GetPageUri(page, ViewModelsRegistry.Register(viewModel))); if (!navigationResult) { //TODO: log and do smth } }