[英]WPF Resource Dictionary XSLT
要在wpf中使用圖像,您可以定義:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="ImageFunTime"
UriSource="../Resources/Images/ImageFunTime.png" />
</
然后在某個地方的應用中,您可以:
var img = (ImageSource)positionsTab.TryFindResource("ImageFunTime");
如何使用嵌入式Xslt文件實現同一目的? 也就是說,資源字典中的語法是什么,因為它顯然不是位圖圖像...
TIA
如何使用嵌入式Xslt文件實現同一目的?
答案 :
Microsoft的XSLT處理器都不支持嵌入式XSLT樣式表。 對於XSLT樣式表,您將需要一個完整的僅XSLT文件。
在XSLT中,人們使用<xsl:key>
指令和key()
函數通過某個字符串值有效地選擇節點,該字符串值唯一地標識了它們。
此轉換 :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="UriSourceByKey"
match="@UriSource" use="../@x:Key"/>
<xsl:variable name="vImageFunTime"
select="key('UriSourceByKey', 'ImageFunTime')"/>
<xsl:template match="/">
<xsl:value-of select="$vImageFunTime"/>
</xsl:template>
</xsl:stylesheet>
當應用於此XML文檔時 :
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="ImageFunTime" UriSource="../Resources/Images/ImageFunTime.png" />
</ResourceDictionary>
產生想要的結果 :
../Resources/Images/ImageFunTime.png
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.