public UIElement Run(string fullyQualifiedNameOfVisualStartingPoint) { Logger.InitializeFromConfiguration(); Cache.InitializeFromConfiguration(); ExceptionHandler.InitializeFromConfiguration(); FrameworkElement element = (FrameworkElement) Activator.CreateInstance(Type.GetType(fullyQualifiedNameOfVisualStartingPoint)); Grid grid = (Grid) element.FindName("LayoutRoot"); NavigationManager manager = new NavigationManager { Source = new Uri("Home", UriKind.Relative) }; grid.Children.Add(manager); NavigationManager.navigationManagerInstance = manager; NavigationManager.navigationManagerInstance.InitializeFromConfiguration(); return element; }
private void ReadConfiguration(XDocument doc) { if (doc.Element("navigationdata").Attribute("enablenavigationmanager").Value == "false") { navigationManagerInstance = null; } else { if (doc.Descendants("frame").Count<XElement>() == 0) { throw new MissingFieldException("No frames have been defined in NavigationMappings.xml."); } foreach (XElement element in doc.Descendants("frame")) { string key = element.Attribute("key").Value; string text1 = element.Attribute("type").Value; if (base.FindName(key) == null) { throw new ArgumentException("The defined frame " + key + " wasn't found, navigation couldn't initialize."); } navigationManagerInstance.Frames.Add(key, (Frame) base.FindName(key)); } foreach (XElement element2 in doc.Descendants("navigationmapping")) { if (element2.Attribute("key") == null) { throw new ArgumentException("Navigationmapping is missing 'key' attribute"); } string str2 = element2.Attribute("key").Value; foreach (XElement element3 in element2.Descendants("viewmapping")) { try { INavigationMapping mapping; if (element3.Attribute("viewmodel") == null) { throw new ArgumentException("Viewmapping is missing 'viewmodel' attribute"); } if (element3.Attribute("view") == null) { throw new ArgumentException("Viewmapping is missing 'view' attribute"); } if (element3.Attribute("frame") == null) { throw new ArgumentException("Viewmapping is missing 'frame' attribute"); } string typeName = element3.Attribute("viewmodel").Value; string str4 = element3.Attribute("view").Value; string str5 = (element3.Attribute("state") == null) ? "" : element3.Attribute("state").Value; string sframe = element3.Attribute("frame").Value; Type type = Type.GetType(typeName); Type type3 = typeof(NavigationMapping<>).MakeGenericType(new Type[] { type }); Frame frame = Enumerable.FirstOrDefault<KeyValuePair<string, Frame>>(navigationManagerInstance.Frames, (Func<KeyValuePair<string, Frame>, bool>) (f => (f.Key == sframe))).Value; if (str5 == string.Empty) { mapping = (INavigationMapping) Activator.CreateInstance(type3, new object[] { str2, str4, frame }); } else { mapping = (INavigationMapping) Activator.CreateInstance(type3, new object[] { str2, str4, frame, str5 }); } navigationManagerInstance.NavigationMappings.Add(mapping); } catch (Exception exception) { throw new ArgumentException("An error occurred while creating the navigation mapping " + str2 + ". Please recheck the mapping.", exception); } } } UriMapper mapper = new UriMapper(); foreach (XElement element4 in doc.Descendants("urimapping")) { string str6 = element4.Attribute("uri").Value; string str7 = element4.Attribute("navigationmappingkey").Value; string str8 = (element4.Attribute("pagetitle") == null) ? "Page title" : element4.Attribute("pagetitle").Value; string str9 = (element4.Attribute("parameters") == null) ? "" : element4.Attribute("parameters").Value; string uriString = str6; string str11 = "/Bromo.Silverlight;component/MVVM/Navigation/NavigationHelper.xaml?key=" + str7; if (str9 != string.Empty) { str11 = str11 + "&" + str9; } str11 = str11 + "&pagetitle=" + str8; Uri uri = new Uri(uriString, UriKind.Relative); Uri uri2 = new Uri(str11, UriKind.Relative); UriMapping item = new UriMapping { MappedUri = uri2, Uri = uri }; mapper.UriMappings.Add(item); } navigationManagerInstance.UriMapper = mapper; } }