- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 WPF 应用程序制作一个主题编辑器。我动态生成 XAML 文件,然后将它们编译到应用程序使用的 DLL 中。用于生成 XAML 文件的代码遵循以下原则:
var dictionary = new ResourceDictionary();
...
dictionary.Add(key, new BitmapImage { UriSource = new Uri(relativePath, UriKind.Relative) });
...
XamlWriter.Save(dictionary, "myDictionary.xaml");
我的问题是 XamlWriter.Save
还序列化 BaseUri
属性:
<BitmapImage BaseUri="{x:Null}" UriSource="Images\myImage.png" x:Key="myImage" />
结果是,当应用程序尝试获取此图像时,它找不到它,因为 BaseUri
未设置。通常,XAML 解析器会设置此属性(通过 IUriContext 接口(interface)),但当它已在 XAML 中显式设置时,解析器不会设置它,因此它保持为 null。
是否有办法阻止 XamlWriter
序列化 BaseUri
属性?
如果我要序列化自定义类,我可以添加一个 ShouldSerializeBaseUri()
方法,或显式实现 IUriContext
(我尝试了这两个选项,它们给出了所需的结果) ,但是如何为 BitmapImage
做到这一点?
作为最后的手段,我可以加载 XAML 文件并使用 Linq to XML 删除属性,但我希望有一个更干净的解决方案。
最佳答案
如果我们不阻止 XamlWriter
写入 BaseUri
属性,而是为其提供不影响图像加载的内容,会怎么样?例如下面的代码:
<Image>
<Image.Source>
<BitmapImage UriSource="Resources/photo.JPG"/>
</Image.Source>
</Image>
似乎相当于
<Image>
<Image.Source>
<BitmapImage BaseUri="pack://application:,," UriSource="Resources/photo.JPG"/>
</Image.Source>
</Image>
尝试
dictionary.Add("Image", new BitmapImage{
BaseUri=new Uri("pack://application:,,"),
UriSource = new Uri(@"Images\myImage.png", UriKind.Relative)
});
如果您尝试将图像源设置为通过代码以这种方式创建的 BitmapImage - 它不会工作。但是 XamlWriter.Save()
生成的 XAML 在 XAML 时确实可以工作:)。好吧,我希望值得一试。
关于.net - 如何防止 XamlWriter.Save 序列化 BaseUri 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6495253/
我是 RAML 的新手,我有一个基本问题: 无法指定一组替代 baseUri(只允许一个)。是否有任何替代方法可以对 API 的多个替代安装进行建模(例如,对于单独的发布周期环境)? 最佳答案 一种方
我刚刚发现通过选择获得的每个元素都需要设置 baseUri。如果将 Document 的 baseUri 应用于每个 Element 会好得多。 Document d = Jsoup.parse(my
我从默认主题 default-bootstrap 开发我的主题。但是当我尝试将商品添加到我的购物车时发生错误。 您知道它可能来自哪里吗? 最佳答案 JS 变量 baseUri 在 global.tpl
每个 Node 实例都有一个 baseURI 属性。ELEMENT_NODE 类型的 Node 实例维护 namespaceURI 属性。 这两个属性对于浏览器管理DOM中的节点有什么意义? 最佳答案
我正在寻找一种将相对基础 Uri 与另一个相对路径结合起来的简洁方法。我尝试了以下方法,但是 Uri(Uri, string) 和 UriBuilder(Uri) 需要绝对 Uris(抛出 Inval
// html data loaded from [http://example.org/some/path] let htmlSource = ` ... ... `; const dom =
我试图将 Google 文档集成到 Windows 应用程序中。在 DocReq 类中有一个名为 baseURI 的属性。我不知道那是什么。另外,如果有任何 C# 中的 Google 电子表格示例,请
MDN doc声称有两种方法可以改变节点 .baseURI属性: 当一个 HTML 在文档中找到标签; (1) 当这是动态创建的新文档时。 (2) 他们没有提供有关如何可以动态完成的解释 (2)。他们
我正在尝试将文件上传到谷歌云存储中的存储桶。 我编写了以下代码来创建 StorageService 并将文件上传到存储桶。 GoogleAuthorizationCodeFlow flow = new
我正在使用 DOMParser 来解析包含相对 URL 的文档,例如表单的 action 属性。因为由 DOMParser 创建的文档的 baseURI 是 null,所以访问 action 属性会产
当我将 XML 文档从磁盘加载到 XDocument 时,该 XDocument 有一个只读属性 BaseUri,它包含原始 XML 文档在磁盘上的位置。换句话说, XDocument doc = X
我在 angular 5.2.1 上工作,我想加载一个 src 来自服务器的图像 HTML 图片加载器.component.ts import { Component, OnInit, I
我正在为 WPF 应用程序制作一个主题编辑器。我动态生成 XAML 文件,然后将它们编译到应用程序使用的 DLL 中。用于生成 XAML 文件的代码遵循以下原则: var dictionary = n
我正在将 Apache FOP 1.0 项目升级到 Apache FOP 2.1。在这个项目中,所有必需的文件都打包在 jar 文件中。 我添加了新的 FopFactoryBuilder 来生成 Fo
我知道 CloudTableClient.BaseUri.AbsoluteUri 返回一个表示主端点的字符串值。但是,如果出现故障,该值是否会更新到辅助端点? 最佳答案 根据document ,Clo
我总是在开发者工具中看到两个实体(baseURI 和 URL)显示相同的 URL,大多数时候都显示在地址栏中。这些是 window.document 对象的属性。那么什么时候基础URI属性是“未定义”
我正在使用 itext7 pdfhtml 将 html 文件转换为 pdf。现在我面临的问题是,我将 converterProperties 的 baseUri 属性设置为指向驻留在“src/main
我总是在开发人员工具中看到两个实体(baseURI 和 URL)显示相同的 URL,大部分时间都显示在地址栏中。有人可以给我提供不同的场景吗?我们什么时候使用一个场景。我看过 mdn 网站的描述,但仍
我正在使用 jsoup 来解析一些 HTML,但我不知道为什么我没有得到我期望的结果。 Q1:我希望输出 URL 为 http://example.com/input/img.jpg ,但它输出 ht
刚刚学习 springboot(和 Java 新手:来自 .NET 世界) 关于 spring-data 和 spring-data-rest 的太 PS 类(class)。一切顺利 与 MS SQl
我是一名优秀的程序员,十分优秀!