2010-05-19 174 views
1

要使用WPF中,你可以定义图片:WPF资源字典XSLT

<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

+0

好问题(+1)。查看我的答案获得完整的解决方案。 :) – 2010-05-19 03:21:36

回答

0

我怎样才能实现与 嵌入的XSLT文件是一回事吗?

答案

  1. 微软的XSLT处理器都没有支持嵌入式XSLT样式表。您将需要一个完整的仅用于XSLT样式表的XSLT文件。

  2. 在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 
+0

我认为OP想要将XSLT样式表声明为资源(如问题中的图像),然后将其转换为C#应用程序。 – 2010-12-30 18:24:44

+0

@Alejandro:那么,如果他问的是什么类型的资源应该是,答案是:字符串。 – 2010-12-30 19:08:11