/// <summary> /// Retrieves the view from the IoC container or tries to create it if not found. /// </summary> /// <remarks> /// Pass the type of view as a parameter and recieve an instance of the view. /// </remarks> protected virtual UIElement GetOrCreateViewType(Type viewType) { DependencyResolver.TryGetInstance(viewType, out var instance); var view = instance as UIElement; if (view == null) { if (viewType.IsInterface || viewType.IsAbstract || !typeof(UIElement).IsAssignableFrom(viewType)) { return new TextBlock { Text = $"Cannot create {viewType.FullName}." } } ; view = (UIElement)System.Activator.CreateInstance(viewType); } if (view is Window window) { ThemeManager.GetResources().ForEach(window.Resources.MergedDictionaries.Add); } view = HydrateView(view); return(view); }