棱镜导航

时间:2013-03-17 12:44:51

标签: wpf prism

我已经开始了第一次使用Prism的尝试,这就是我已经完成的事情:

@ 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是一个自己的ClassProject,UserControland有一个menue。我想在CenterRegion中用menueitem的命令注入一个视图,但我真的不知道如何。我是否还必须将Topbar声明为模块?

由于

1 个答案:

答案 0 :(得分: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;
    }