大前端

前端学习之家-大前端

prism 搭建prism项目

1 新建wpf应用程序

2 通过nuget导入prism.unity库

3 在项目中新建Views文件夹,并将Window.xaml拖到该文件夹中,修改MainWindow.xaml中的类的定义,增加Views

<Window x:Class="Prism.Regions.Views.MainWindow"

4 同样在后台代码中也修改MainWindow的命名空间

5 在App.xaml中删除StartupUri="MainWindow.xaml"

6 在App.xaml中定义prism库

 xmlns:prism="http://prismlibrary.com/"

7 将App.xaml中的Application换成prism:PrismApplication

<prism:PrismApplication x:Class="Prism.Regions.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Prism.Regions"
             xmlns:prism="http://prismlibrary.com/"
            >
    <Application.Resources>
         
    </Application.Resources>
</prism:PrismApplication>

8 将App.xaml的后台代码中的Application换成PrismApplication,并导入prism.unity库

9 编译下程序后,根据提示实现PrismApplication的抽象方法

 10 修改两个方法如下

using Prism.Ioc;
using Prism.Regions.Views;
using Prism.Unity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Prism.Regions
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            
        }
    }
}

11 运行,应该可以打开MainWindow

发表评论:

Copyright Your WebSite.Some Rights Reserved.