06、ActivationDeactivation

news/2024/7/5 2:10:36

  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


http://lihuaxi.xjx100.cn/news/236348.html

相关文章

Kong Api 网关使用 docker 部署

Kong 镜像: https://hub.docker.com/_/kong 官网给定的用户安装手册上并没有设置 PG 的密码&#xff0c;导致如下问题无法启动 nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:277: [PostgreSQL error] failed to >retrieve server_version_num…

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

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

php 所有魔术方法,PHP常用的魔术方法及规则

转&#xff1a;https://www.cnblogs.com/wanglijun/p/10926303.html1. __construct 具有构造函数的类会在每次创建新对象时先调用此方法;初始化工作执行。2. __desstruct 对象的所有引用都被删除或者当对象被显式销毁时执行。3.__call()在对象中调用一个不可访问方法时&#xf…

Room Database完全使用手册

前言 Android数据持久层直接使用SQLite很麻烦&#xff0c;Google官方推出了Room&#xff0c; Google对Room的定义&#xff1a; The Room persistence library provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of …

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

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

php监听订单状态,ecshop数据库订单状态判断

order_info 表刚下完订单order_status 0shipping_status 0pay_status 0取消order_status 2shipping_status 0pay_status 0确认order_status 1shipping_status 0pay_status 0已付款order_status 1shipping_status 0pay_status 2配货中order_status 1shipping_status 3pay_status…

firefox下的调试工具

2019独角兽企业重金招聘Python工程师标准>>> vue-devtools https://addons.mozilla.org/en-US/firefox/user/13100848/ 转载于:https://my.oschina.net/u/3371661/blog/3003299

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

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