欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Wpf,Unity6

程序员文章站 2022-04-30 12:27:58

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="commonservicelocator" version="1.2" targetframework="net452" />
<package id="prism" version="5.0.0" targetframework="net452" />
<package id="prism.composition" version="5.0.0" targetframework="net452" />
<package id="prism.interactivity" version="5.0.0" targetframework="net452" />
<package id="prism.mvvm" version="1.0.0" targetframework="net452" />
<package id="prism.pubsubevents" version="1.0.0" targetframework="net452" />
<package id="prism.unityextensions" version="5.0.1" targetframework="net452" />
<package id="unity" version="3.5.1404.0" targetframework="net452" />
</packages>

 

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<shell>();
        }

        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<igetstudentlist, studentvm>(new containercontrolledlifetimemanager());
            this._regionmanager.registerviewwithregion("maregion",typeof(maview));
        }
    }
}
<usercontrol x:class="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">
    <grid background="red">
        <datagrid x:name="dg" itemssource="{binding stulist}"
                  autogeneratecolumns="true" borderbrush="yellow" borderthickness="5">
           
        </datagrid>
    </grid>
</usercontrol>