mirror of https://github.com/AMT-Cheif/Stylet.git
Split out ViewManager.LocateViewForModel, and fix a sample
This commit is contained in:
parent
ea8cbd41f7
commit
5884592c07
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using StyletIoC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -8,11 +9,11 @@ namespace Stylet.Samples.OverridingViewManager
|
|||
{
|
||||
public class Bootstrapper : Bootstrapper<ShellViewModel>
|
||||
{
|
||||
protected override void ConfigureIoC(StyletIoC.IStyletIoCBuilder builder)
|
||||
protected override void ConfigureIoC(IStyletIoCBuilder builder)
|
||||
{
|
||||
base.ConfigureIoC(builder);
|
||||
|
||||
builder.Bind<IViewManager>().To<CustomViewManager>();
|
||||
builder.Bind<IViewManager>().To<CustomViewManager>().InSingletonScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -42,7 +42,7 @@ namespace Stylet
|
|||
public interface IConductor<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Active the given item
|
||||
/// Activate the given item
|
||||
/// </summary>
|
||||
/// <param name="item">Item to activate</param>
|
||||
void ActivateItem(T item);
|
||||
|
|
|
@ -63,18 +63,24 @@ namespace Stylet
|
|||
}
|
||||
}
|
||||
|
||||
public virtual UIElement CreateViewForModel(object model)
|
||||
public virtual Type LocalViewForModel(Type modelType)
|
||||
{
|
||||
var modelName = model.GetType().FullName;
|
||||
var viewName = Regex.Replace(modelName, @"ViewModel", "View");
|
||||
var viewName = Regex.Replace(modelType.FullName, @"ViewModel", "View");
|
||||
// TODO: This might need some more thinking
|
||||
var viewType = AssemblySource.Assemblies.SelectMany(x => x.GetExportedTypes()).FirstOrDefault(x => x.FullName == viewName);
|
||||
|
||||
if (viewType == null)
|
||||
throw new Exception(String.Format("Unable to find a View with type {0}", viewName));
|
||||
|
||||
return viewType;
|
||||
}
|
||||
|
||||
public virtual UIElement CreateViewForModel(object model)
|
||||
{
|
||||
var viewType = this.LocalViewForModel(model.GetType());
|
||||
|
||||
if (viewType.IsInterface || viewType.IsAbstract || !typeof(UIElement).IsAssignableFrom(viewType))
|
||||
throw new Exception(String.Format("Found type for view : {0}, but it wasn't a class derived from UIElement", viewType.Name));
|
||||
throw new Exception(String.Format("Found type for view: {0}, but it wasn't a class derived from UIElement", viewType.Name));
|
||||
|
||||
var view = (UIElement)IoC.GetInstance(viewType, null);
|
||||
|
||||
|
|
Loading…
Reference in New Issue