2013-03-17 480 views
0

我開始了我的第一次嘗試用棱鏡,這就是我沒有完成:棱鏡導航

@ Bootstrapper.cs

ModuleCatalog catalog = new ModuleCatalog(); 
catalog.AddModule(typeof(ExampleModule)); 

@ ExampleModule.cs

public void Initialize() 
     { 
      regionManager.RegisterViewWithRegion("TopBarRegion", typeof(StandardTopBar)); 
      regionManager.RegisterViewWithRegion("CenterRegion", typeof(PersonStammdatenControl)); 
      regionManager.RegisterViewWithRegion("BottomBarRegion", typeof(Bottombar)); 
     } 

StandardTopbar是一個擁有UserControland自己的ClassProject的菜單。我想用Menueitem的一個命令在CenterRegion中注入一個視圖,但我真的不知道如何。我是否也必須將Topbar聲明爲模塊?

感謝

回答

2

這是一個簡單的方法:

@Module:

protected override void RegierTypes() 
    { 
    base.Container.RegisterType<IMainPageViewModel, MainPageViewModel>(); 
    var viewModel = container.Resolve<IMainPageViewModel>(); 
    RegionManager.Regions[RegionNames.ContentRegion].Add(viewModel.View); 
} 

@ViewModel:

private readonly IEventAggregator eventAggregator; 
    private readonly IMainPage view; 

public MainPageViewModel(IMainPage view, 
IEventAggregator eventAggregator) : base(view) 
    { 
    this.view = view; 
    this.eventAggregator = eventAggregator; 
} 

public interface IMainPage : IView 
    { 

    } 

public interface IView 
{ 
    IViewModel ViewModel { get; set; } 
} 

public interface IViewModel 
{ 
    IView View { get; set; } 
} 

@bootstrapper:

protected override IModuleCatalog CreateModuleCatalog() 
    { 
     ModuleCatalog catalog = new ModuleCatalog(); 
     catalog.AddModule(typeof(MainModule)); 

     return catalog; 
    }