当前位置: 首页 > 编程日记 > 正文

06、ActivationDeactivation

1、将App.xaml中的StartupUri="MainWindow.xaml"删除。

2、使用NuGet安装Prism.Wpf、Prism.Core、Prism.Unity。

3、添加类“Bootstrapper”,编辑如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Windows;
 7 using Microsoft.Practices.Unity;
 8 using ActivationDeactivation.Views;
 9 using Prism.Unity;
10 
11 namespace ActivationDeactivation
12 {
13     class Bootstrapper:UnityBootstrapper
14     {
15         protected override DependencyObject CreateShell()
16         {
17             return Container.Resolve<MainWindow>();
18         }
19 
20         protected override void InitializeShell()
21         {
22             Application.Current.MainWindow.Show();
23         }
24     }
25 }

4、创建文件夹Views,将MainWindow.xaml移动到此文件夹中。向Views文件夹中添加ViewA.xaml,ViewB.xaml。

 1 <Window x:Class="ActivationDeactivation.Views.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6         xmlns:local="clr-namespace:ActivationDeactivation"
 7         xmlns:prism="http://prismlibrary.com/"
 8         mc:Ignorable="d"
 9         Title="MainWindow" Height="450" Width="800">
10     <DockPanel LastChildFill="True">
11         <StackPanel>
12             <Button Content="Activate ViewA" x:Name="btnViewA" Click="BtnViewA_OnClick"/>
13             <Button Content="Deactivate ViewA" x:Name="btnDeactiveViewA" Click="BtnDeactiveViewA_OnClick"/>
14             <Button Content="Activate ViewB" x:Name="btnViewB"  Click="BtnViewB_OnClick"/>
15             <Button Content="Deactivate ViewB" x:Name="btnDeactiveViewB" Click="BtnDeactiveViewB_OnClick"/>
16         </StackPanel>
17         <ContentControl prism:RegionManager.RegionName="ContentRegion" HorizontalAlignment="Center" VerticalAlignment="Center" />
18     </DockPanel>
19 </Window>
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Windows;
 7 using System.Windows.Controls;
 8 using System.Windows.Data;
 9 using System.Windows.Documents;
10 using System.Windows.Input;
11 using System.Windows.Media;
12 using System.Windows.Media.Imaging;
13 using System.Windows.Navigation;
14 using System.Windows.Shapes;
15 using Microsoft.Practices.Unity;
16 using Prism.Regions;
17 
18 namespace ActivationDeactivation.Views
19 {
20     /// <summary>
21     /// MainWindow.xaml 的交互逻辑
22     /// </summary>
23     public partial class MainWindow : Window
24     {
25         private IUnityContainer _container;
26         private IRegionManager _regionManager;
27         private IRegion _region;
28 
29         private ViewA _viewA;
30         private ViewB _viewB;
31         public MainWindow(IUnityContainer unityContainer,IRegionManager regionManager)
32         {
33             InitializeComponent();
34             _container = unityContainer;
35             _regionManager = regionManager;
36             
37 
38             this.Loaded += MainWindow_Loaded;
39         }
40 
41         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
42         {
43             _viewA = _container.Resolve<ViewA>();
44             _viewB = _container.Resolve<ViewB>();
45 
46             _region = _regionManager.Regions["ContentRegion"];
47 
48             _region.Add(_viewA);
49             _region.Add(_viewB);
50         }
51 
52         private void BtnViewA_OnClick(object sender, RoutedEventArgs e)
53         {
54             _region.Activate(_viewA);
55         }
56 
57         private void BtnDeactiveViewA_OnClick(object sender, RoutedEventArgs e)
58         {
59             _region.Deactivate(_viewA);
60         }
61 
62         private void BtnViewB_OnClick(object sender, RoutedEventArgs e)
63         {
64             _region.Activate(_viewB);
65         }
66 
67         private void BtnDeactiveViewB_OnClick(object sender, RoutedEventArgs e)
68         {
69             _region.Deactivate(_viewB);
70         }
71     }
72 }
 1 <UserControl x:Class="ActivationDeactivation.Views.ViewA"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 5              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 6              xmlns:local="clr-namespace:ActivationDeactivation.Views"
 7              mc:Ignorable="d" 
 8              d:DesignHeight="450" d:DesignWidth="800">
 9     <Grid>
10             <TextBlock Text="View A" FontSize="38"/>
11     </Grid>
12 </UserControl>
 1 <UserControl x:Class="ActivationDeactivation.Views.ViewB"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 5              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 6              xmlns:local="clr-namespace:ActivationDeactivation.Views"
 7              mc:Ignorable="d" 
 8              d:DesignHeight="450" d:DesignWidth="800">
 9     <Grid>
10             <TextBlock Text="View B" FontSize="38"/>
11     </Grid>
12 </UserControl>

5、修改App.xaml

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Configuration;
 4 using System.Data;
 5 using System.Linq;
 6 using System.Threading.Tasks;
 7 using System.Windows;
 8 
 9 namespace ActivationDeactivation
10 {
11     /// <summary>
12     /// App.xaml 的交互逻辑
13     /// </summary>
14     public partial class App : Application
15     {
16         protected override void OnStartup(StartupEventArgs e)
17         {
18             base.OnStartup(e);
19 
20             var bootstrapper = new Bootstrapper();
21             bootstrapper.Run();
22         }
23     }
24 }

转载于:https://www.cnblogs.com/bjxingch/articles/9547741.html

相关文章:

Git 学习笔记一

Git的基本配置和使用 一、git add ;git commit;git commit -a(默认跟踪修改直接提交(不包括新文件))。 二、tig命令 查看修改记录的前端工具&#xff0c;方面查看修改记录。相当于git log –p。 三、git config --global alias.ci "commit -a -v"添加命令别名&#x…

vb 取得计算机名及目录

Public gCompName 取得计算机名及Windows目录 Dim i% Dim c$ Dim cSql As String Dim cProduct As String c Space(256) i GetComputerName(c, 256) gCompName Trim(c) gCompName Left(gCompName, Len(gCompName) - 1) 读取MAC地址 Dim…

速率单位和信息量单位区分

网络技术钟的速率指的是数据的传送速率&#xff0c;也称为数据率或比特率。 单位是bit/s 比特每秒 也写作b/s 或bps(bit per second) 当数据率较高时 常常在bit/s前面加一个字母&#xff0c;如 k 10^3 M 10^6 G 10^9 T 10^12 P 10^15 …… 数据量往往用字节B作为度量单位…

python 自动生成C++代码 (代码生成器)

python 代码自动生成的方法 &#xff08;代码生成器&#xff09; 遇到的问题 工作中遇到这么一个事&#xff0c;需要写很多C的底层数据库类&#xff0c;但这些类大同小异&#xff0c;无非是增删改查&#xff0c;如果人工来写代码&#xff0c;既费力又容易出错&#xff1b;而借用…

WPF实用指南二:移除窗体的图标

原文:WPF实用指南二&#xff1a;移除窗体的图标WPF没有提供任何功能来移除窗体上的icon图标。一般的做法是设置一个空白的图标&#xff0c;如下图1: 这种做法在窗体边框与标题之间仍然会保留一片空白。比较好的做法是使用Win32API提供的函数来移除这个图标。使用如下的代码&…

什么是EAI?

什么是EAI(enterprise application integration)企业应用集成? EAI是将基于各种不同平台、用不同方案建立的异构应用集成的一种方法和技术。EAI通过建立底层结构&#xff0c;来联系横贯整个企业的异构系统、应用、数据 源等&#xff0c;完成在企业内部的 ERP、CRM、SCM、数据库…

C# 中的委托和事件

引言 委托 和 事件在 .Net Framework中的应用非常广泛&#xff0c;然而&#xff0c;较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就像是一道槛儿&#xff0c;过了这个槛的人&#xff0c;觉得真是太容易了&#xff0c;而没有过去的人每次见到委托和事件就觉…

零代价修复海量服务器的内核缺陷——UCloud内核热补丁技术揭秘

下述为UCloud资深工程师邱模炯在InfoQ架构师峰会上的演讲——《UCloud云平台的内核实践》中非常受关注的内核热补丁技术的一部分。给大家揭开了UCloud云平台内核技术的神秘面纱。 如何零代价修复海量服务器的Linux内核缺陷&#xff1f; 对于一个拥有成千上万台服务器的公司&…

软件工程技术基础-(软件复用技术)

软件可重用问题&#xff0c;包括源程序代码重用、静态库重用和组建重用。 源程序代码重用是直接将其他项目或系统开发完成的代码复制过来&#xff0c;直接使用。 限制源程序代码重用技术使用的关键因素是要考虑代码的语言实现&#xff0c;以及源代码 公开可能带来的知识产权问题…

Parcelable与Serializable的比较

Parcel: Android中的序列化方式&#xff0c;可用于跨进程传输 Parcelable 进程间 如&#xff1a;想从一个第三方app拿进程回来 Serializable 进程内

20140725 快速排序时间复杂度 sTL入门

1、快速排序的时间复杂度(平均时间复杂度为) 数组本身就有序时&#xff0c;效果很差为O(n^2) 2、STl入门 &#xff08;1&#xff09; C内联函数(inline)和C中宏(#define)区别 内联函数有类型检查&#xff0c;宏定义没有&#xff1b;C编程尽量使用内联函数 template <class T…

小编带你进入强如 Disruptor 也发生内存溢出?

前言OutOfMemoryError 问题相信很多朋友都遇到过&#xff0c;相对于常见的业务异常&#xff08;数组越界、空指针等&#xff09;来说这类问题是很难定位和解决的。 本文以最近碰到的一次线上内存溢出的定位、解决问题的方式展开&#xff1b;希望能对碰到类似问题的同学带来思路…

数据库反规范设计

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd> 反规范化设计 为了提升性能而使用反规范化设计 常用方法&#xff1a; A、在多个表中存储某个字段的副本 B、在父表中存储汇总值 C、将活动数据和历史数据分开存储 D、应用程序本地缓…

安卓的两种界面编写方式对比

1.XML进行描述 优点是可以直接在Android studio Preview 栏中查看效果(所见即所得&#xff0c;但是不是所有的都可以立刻看到效果) 注意&#xff1a;包含两种方式-编辑layout文件夹下的XML文件 和 直接从下图的图形化界面操作 2.Java/Kotlin代码进行编写 随着学习的深入&#x…

对象***已断开连接或不在该服务器上 的解决方案之一

使用VS2008在发布网站的时候&#xff0c;出现了这样的一个错误&#xff0c;先前一直是OK的。网上找了老半天&#xff0c;几乎没有此问题的解决办法。很是郁闷。只能一个一个地进行编译。单个层Build是OK的&#xff0c;整个Solution的Rebuild也是OK的&#xff0c;一开始使用VS自…

Web.XML文件中关于代码提示的一些问题

1. 问题描述 在进行ssm的整合时&#xff0c;我发现在web.xml文件中里按了alt/以后没有下面的提示&#xff1a;这样真的很不爽。。。于是弄了半天&#xff08;主要是等着&#xff09;终于解决了&#xff0c;特此写篇博客记录下。 2. 解决方案 在eclipse中安装Spring IDE的插件&a…

安卓开发之点九图

Nine-Patch图 xxx.9.png 口诀&#xff1a;左上进行拉伸&#xff0c;右下进行显示。

ImportError: No module named images

&#xff3b;问题&#xff3d; 在使用学习wxPython时&#xff0c;一个Dem抱有如题所示错误 &#xff3b;解决&#xff3d; images 只不过是wxpython自带demo中的一个文件 体验wxpython IN action的时候ImportError: No module named images替换为import wx.py.images as images…

从 Java 到 Scala(二):object

本文由 Rhyme 发表在 ScalaCool 团队博客。 object是一种让静态回归常态、打破模式、天然的语言特性。 其实在写这篇文章之前&#xff0c;我思绪万千&#xff0c;迟迟不能落笔&#xff0c;总想着自己会不会遗漏了某个知识点&#xff0c;或者有讲得不太那么准确的地方&#xff0…

Python获取屏幕分辨率大小

获取屏幕大小有两种方法可以办到: 1.wxPython里的 2.win32api 1 #coding:gb23122 #wxApp.py 3 #author: aoogur4 importos5 importwx6 fromwin32api importGetSystemMetrics7 8 classFrame(wx.Frame):9 def__init__(self):10 wx.Frame.__init__(self,None,-1,title"wxApp.…

安卓事件传递机制

1.触摸事件 MotionEvent ACTION_DOWN:按下 ACTION_MOVE:移动 ACTION_UP:松开 2.以上三个触摸事件都会经历三个函数 事件分发&#xff08;Dispatch&#xff09;&#xff1a;dispatchTouchEvent 事件拦截 &#xff08;Intercept&#xff09;&#xff1a;onInterceptTouchEvent 事…

财务软件的管理监督

随着现代企业的发展&#xff0c;企业财务管理的内涵、外延、功能及其地位发生了深刻的变化&#xff0c;强化企业的财务管理已经成为现代企业在激烈的市场竞争中得以生存和发展、现代企业制度得以保证和实施的重要环节。财务管理软件的应用已经非常普及了。 现代企业财务管…

[Vue CLI 3] 插件编写实战和源码分析

当你看过了官方的几个插件之后&#xff0c;慢慢地&#xff0c;其实你也有需求了。 那如何编写一个 Vue CLI 3 的插件呢&#xff1f;本文代码已经放到 github 上&#xff0c;地址&#xff1a;https://github.com/dailynodej... 我们建一个文件夹&#xff0c;取名 vue-cli-plugin…

突然想起99年的那次离别

今天妹妹离开成都回家了突然发现某一件事情又那么蹿了出来了&#xff0c;是99年的秋天那次&#xff0c;同f到成都且分开的那短暂的2天&#xff01;很多年了&#xff0c;不知道是忘记了再回忆起&#xff0c;还是一直埋在最深处&#xff0c;瞬间又重现&#xff01;想了&#xff0…

列表组件之ListView

1.ListView是什么 一个显示可滚动项目的视图组件系统使用Adapter(适配器)将列表项目插入列表适配器从来源提取内容 下图从MVC分析的话&#xff0c;ListView相当于View&#xff0c;Adapter相当于Controller&#xff0c;data相当于Model 缺点&#xff1a;屏幕里面只能展示有限个…

C#杂记系列之日期函数

//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString("d"); //2008年4月24日 16:30:15 System.DateTime.Now.ToString("F"); //2008年4月24日 16:30 System.DateTime.Now.ToString("f"); /…

对着电脑笑了二十分钟(2)

25、有一次我大叔见我小姑在搽大宝&#xff0c;突然大叫一声&#xff1a;“你皮肤这么好&#xff0c;还用护舒宝啊&#xff1f;”26、老师留下作业&#xff0c;我不会做就抄别人的&#xff0c;然后去办公室交作业&#xff0c;看见老师说&#xff1a;“我抄完了&#xff01;”27…

ORACLE临时表空间

https://www.cnblogs.com/kerrycode/p/4006840.html转载于:https://www.cnblogs.com/elontian/p/9564296.html

列表组件之RecyclerView

灵活体现在 ListView 只支持上下滑动 RecyclerView 可以左右滑动&#xff0c;可以瀑布流 并且默认支持布局&#xff1a;线性布局、网络布局 RecyclerView将很多固定模式的地方抽象出来了&#xff0c;如用于动画的ItemAnimator和用于布局的LayoutManager Adapet的特点 1.ViewHo…