这里稍微复杂了点,定义视图A的过程是一样的:

<UserControl x:Class="ViewInjection.Views.ViewA"
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:ViewInjection.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Text="View A" FontSize="38" />
</Grid>
</UserControl>

但是与前面不同的是,需要点击按钮之后才能显示,这个在MainWindow的后台文件中体现:

 
public partial class MainWindow : Window
{
IContainerExtension _container;
IRegionManager _regionManager; public MainWindow(IContainerExtension container, IRegionManager regionManager)
{
InitializeComponent();
_container = container;
_regionManager = regionManager;
} private void Button_Click(object sender, RoutedEventArgs e)
{
var view = _container.Resolve<ViewA>();
var region = _regionManager.Regions["ContentRegion"];
region.Add(view);
}
}

这里所称的注入,首先是在构造函数中注入了容器和区域管理器,然后在Button的后台中,先生成View的实例,再找到Region,最后向Region中Add(View)。

由些看来,View Injection的方法更透明,也就是说这个过程更可控,在下面的情况下,建议使用Injection。

不知道为什么在引用之后没法插入文字了。

有道翻译:

例如,作为应用程序逻辑的结果,对何时创建和显示视图,或何时需要从区域中删除视图进行显式或编程控制。

将相同视图的多个实例显示到一个区域中,每个视图实例绑定到不同的数据。

控制添加哪个区域实例的视图(例如,如果您想将客户详细信息视图添加到特定的客户详细信息区域)。请注意,

此场景需要本主题后面描述的范围区域。

    • Explicit or programmatic control over when a view is created and displayed, or when you need to remove a view from a region, for example, as a result of application logic.
    • To display multiple instances of the same views into a region, where each view instance is bound to different data.
    • To control which instance of a region a view is added (for example, if you want to add customer detail view to a specific customer detail region). Note that
      this scenario requires scoped regions described later in this topic.

Prism Sample 5 View Injection的更多相关文章

  1. Prism框架中View与Region关联的几种方式

    Prism.Regions命名空间下有2个重要接口:IRegionManager.IRegion IRegionManager接口中的方法与属性:AddToRegion().RegisterViewW ...

  2. 【二】注入框架RoboGuice使用:(Your First View Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([一]注入框架RoboGuice使用:(A brief example of what RoboGuice does)),今天我们我看下View的注 ...

  3. Prism 4 文档 ---第7章 组成用户界面

    一个应用程序的用户界面(UI)可以通用以下几种模式之一来构建: 窗体所需要所有的控件都包含在一个单独的XAML文件中,在设计时组合这个窗体. 窗体的逻辑区域被分割到单独的部分中,通常指哟过户控件.这些 ...

  4. 1: 介绍Prism5.0 Introduction to the Prism Library 5.0 for WPF(英汉对照版)

     Prism provides guidance designed to help you more easily design and build rich, flexible, and easy- ...

  5. 下载并安装Prism5.0库 Download and Setup Prism Library 5.0 for WPF(英汉对照版)

    Learn what’s included in Prism 5.0 including the documentation, WPF code samples, and libraries. Add ...

  6. Android 主题动态切换框架:Prism

    Prism(棱镜) 是一个全新的 Android 动态主题切换框架,虽然是头一次发布,但它所具备的基础功能已经足够强大了!本文介绍了 Prism 的各种用法,希望对你会有所帮助,你也可以对它进行扩展, ...

  7. 4: 模块化应用程序开发 Modular Application Development Using Prism Library 5.0 for WPF (英汉对照版)

    A modular application is an application that is divided into a set of loosely coupled functional uni ...

  8. Prism5.0新内容 What's New in Prism Library 5.0 for WPF(英汉对照版)

    Prism 5.0 includes guidance in several new areas, resulting in new code in the Prism Library for WPF ...

  9. Prism.WPF -- Prism框架使用(下)

    本文参考Prism官方示例 命令使用 Prism提供了两种命令:DelegateCommand和CompositeCommand. DelegateCommand DelegateCommand封装了 ...

  10. Prism.WPF -- Prism框架使用(上)

    本文参考Prism官方示例 创建Prism项目 将App.xaml中的WPF标准Application替换为PrismApplication,移除StartupUri属性: 将App.xaml.cs中 ...

随机推荐

  1. mysql驱动下载

    下载地址:https://dev.mysql.com/downloads/connector/j/ 下载步骤:Select Operating System: Platform Independent

  2. 在Vue的mixins(混入)里面调用Vuex(@/store/index.js)的函数

    第一步:在mixin.js里面引入 mapMutations 第二步:跟组件内调用一样,在methods里面写 "...mapMutations(['xxx'])",   然后LZ ...

  3. Unity各种功能实现之一:对话系统

    最近根据网上的教程学习了一下Unity中的对话系统,将其中一些关键点记录下来作为参考,以后可在此基础上添加更多功能. 1.UI部分的设置. 对话框由一个panel下面的text和image组成.can ...

  4. SEGGER_RTT_printf()函数添加打印浮点数功能

    SEGGER 的实时传输 (RTT) 是一种用于嵌入式应用程序中交互式用户 I/O 的技术.它以非常高的性能结合了 SWO 和半主机的优势.但是在笔者使用时(RTT v758版本),其暂时不支持浮点数 ...

  5. 了解RTT 和RTO 对于TCP 重传的影响

    前言 我们已经在很多地方了解TCP 的功能和常用字段.但是TCP 传输发生的异常情况总是让我们很棘手,不知改如何处理.陷入迷茫之中.本文章只针对RTT 和RTO 做了解. 描述  RTT (Round ...

  6. database.property文件

    注意修改用户名密码 mysql8的版本要注意配置时区 此文件放置连接数据库的相关参数 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://l ...

  7. 传输安全HTTPS

    为什么要有 HTTPS 为什么要有 HTTPS?简单的回答是:"因为 HTTP 不安全".HTTP 怎么不安全呢? 通信的消息会被窃取,无法保证机密性(保密性):由于 HTTP 是 ...

  8. Android笔记--外部存储空间

    存储文件的操作 外部存储空间 私有存储空间和公共存储空间 外部存储空间分为私有+公有 保存文件到外部存储空间的相关代码操作: 私有空间: 公有空间: 记得增加权限(Android_Manifest.x ...

  9. BeautifulSoup模块的使用方法

    本篇文章主要讲bs4模块(BeautifulSoup),这个模块能做么呢?用一句话来概括的话:beautifulsoup4 从HTML或XML文件中提取数据的Python库,用它来解析爬取回来的xml ...

  10. 从零开始学Java系列之Java是什么?它到底是个啥?

    全文大约[5000]字,不说废话,只讲可以让你学到技术.明白原理的纯干货!文章带有丰富案例及配图,只为让你更好的理解和运用文中的技术概念,给你带来具有足够的思想启迪...... ----------- ...