Prism Sample 5 View Injection
这里稍微复杂了点,定义视图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的更多相关文章
- Prism框架中View与Region关联的几种方式
Prism.Regions命名空间下有2个重要接口:IRegionManager.IRegion IRegionManager接口中的方法与属性:AddToRegion().RegisterViewW ...
- 【二】注入框架RoboGuice使用:(Your First View Injection)
上一篇我们简单的介绍了一下RoboGuice的使用([一]注入框架RoboGuice使用:(A brief example of what RoboGuice does)),今天我们我看下View的注 ...
- Prism 4 文档 ---第7章 组成用户界面
一个应用程序的用户界面(UI)可以通用以下几种模式之一来构建: 窗体所需要所有的控件都包含在一个单独的XAML文件中,在设计时组合这个窗体. 窗体的逻辑区域被分割到单独的部分中,通常指哟过户控件.这些 ...
- 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- ...
- 下载并安装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 ...
- Android 主题动态切换框架:Prism
Prism(棱镜) 是一个全新的 Android 动态主题切换框架,虽然是头一次发布,但它所具备的基础功能已经足够强大了!本文介绍了 Prism 的各种用法,希望对你会有所帮助,你也可以对它进行扩展, ...
- 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 ...
- 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 ...
- Prism.WPF -- Prism框架使用(下)
本文参考Prism官方示例 命令使用 Prism提供了两种命令:DelegateCommand和CompositeCommand. DelegateCommand DelegateCommand封装了 ...
- Prism.WPF -- Prism框架使用(上)
本文参考Prism官方示例 创建Prism项目 将App.xaml中的WPF标准Application替换为PrismApplication,移除StartupUri属性: 将App.xaml.cs中 ...
随机推荐
- JSTl_概述和JSTL_常用便签if
概念: JavaServer Pages Tag Library JSP 标准标签片*是由 Apache 组织提俱的开源的免费的 jsp 标签 <标签> 作用:用于简化和替换 jsp 页面 ...
- fiddler动态调试js
背景 昨天获取到的网易云音乐站点的请求内容居然是加密的, 就需要动态的调试js找出params很secSeky未加密之前的内容. 调试方法 调试之前需要在目标浏览器上部署上fiddler的根证 ...
- layui 手册
https://layui.yii666.com/doc/modules/layer.html
- 在Windows上访问linux的共享文件夹
1. https://blog.csdn.net/weixin_44147924/article/details/123692155
- python selenium 操作文件上传,并发操作时,文件选择窗口混乱解决方案
上传文件 使用的是 python + autoit 模块,这种方式有一个问题,当出现多条任务同时选择文件上传的时候,无法判断那个文件选择窗口的归属,从而出现上传了错误的文件! 解决方法: 要上载文件而 ...
- 对于如何在IDEA中给Terminal添加git的详解
具体步骤 1.配置本机环境变量 进入到环境变量的设置界面,然后找到下面的Path变量,双击点开: 然后新建一个变量,路径定义到git的目录下面的bin目录下: 2.WIN+R,然后输入cmd,进入终端 ...
- Kakao Brain 的开源 ViT、ALIGN 和 COYO 文字-图片数据集
最近 Kakao Brain 在 Hugging Face 发布了一个全新的开源图像文本数据集 COYO,包含 7 亿对图像和文本,并训练了两个新的视觉语言模型 ViT 和 ALIGN ViT 和 A ...
- 通过 poe 免费使用ChatGPT、GPT-4
poe 是由美版知乎 Quora 构建的AI 产品,提供实时在线与多个AI 机器人交流.Quora 于去年 12 月首次推出Poe 作为封闭测试版,并于2月份向所有 iOS 用户开放.支持 web 端 ...
- 关于springboot使用mybatis查询出现空指针,以及debug出现All Elements all Null的解决方法
数据库中命名方式是带有下划线 ,然后在实体类中使用的是驼峰命名法 ,那么就需要在application.yml文件中加上 自闭了,那么简单的问题,没了解过真是摸不着头脑
- 基于 ByteHouse 构建实时数仓实践
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 随着数据的应用场景越来越丰富,企业对数据价值反馈到业务中的时效性要求也越来越高,很早就有人提出过一个概念: 数据的 ...