在 WPF 应用程序中使用包 URI 真的很重要吗? [英] Is it really important to use pack URIs in WPF apps?

查看:21
本文介绍了在 WPF 应用程序中使用包 URI 真的很重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们为什么要使用那些,而不是普通的?

Why should we use those, rather than ordinary ones?

使用它有什么好处:

new Uri("pack://application:,,,/File.xaml");

以上:

new Uri("/File.xaml", UriKind.Relative);

推荐答案

第一个 - 您可以通过在三个逗号后添加程序集名称来使用交叉程序集.因此,您可以创建一个具有通用样式和其他 XAML 优点的共享库,这些库可以在多个程序集之间共享.

The first one - you can use cross-assembly by adding a assembly-name after the three commas. So, you can create a shared library with common styles and other XAML-goodness that can be shared between several assemblies.

语法是这样的:

pack://application:,,,/Common;component/CommonResources.xaml

其中 Common 是程序集的名称,component 之后的所有内容都是该程序集中到映射资源的路径.后者只能在同一个程序集中使用(并且应该是首选).

where Common is the name of the assembly and everything after component is the path inside that assembly to the mapped resource. The latter can only be used inside the same assembly (and should be preferred).

我经常将它用于位于多个模块类型程序集之上的公共程序集中的 ResourceDictionaries.

I use it a lot for ResourceDictionaries residing in a common assembly above several module-type assemblies.

这篇关于在 WPF 应用程序中使用包 URI 真的很重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆