Wpf,Unity6











 

using Microsoft.Practices.Prism.UnityExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using MA;
using MB;

namespace WpfApplication6
{
    public class WpfBootstrapper:UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.TryResolve();
        }

        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();
            ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
            moduleCatalog.AddModule(typeof(ModuleA));
            moduleCatalog.AddModule(typeof(ModuleB));
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return base.CreateModuleCatalog();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            App.Current.MainWindow = (Window)this.Shell;
            App.Current.MainWindow.Show();
        }
    }
}
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using MA.Views;
using MA.ViewModel;

namespace MA
{
    public class ModuleA : IModule
    {
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;
        public ModuleA(IUnityContainer container,IRegionManager regionManager)
        {
            _container = container;
            _regionManager = regionManager;
        }
        public void Initialize()
        {
            _container.RegisterType(new ContainerControlledLifetimeManager());
            this._regionManager.RegisterViewWithRegion("MARegion",typeof(MAView));
        }
    }
}
"MA.Views.MAView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MA.Views"
             mc:Ignorable="d" 
             d:DesignHeight="100" d:DesignWidth="300">
    "Red">
        "dg" ItemsSource="{Binding StuList}"
                  AutoGenerateColumns="True" BorderBrush="Yellow" BorderThickness="5">
           
        
    

 

你可能感兴趣的:(Wpf,Unity6)