开发者

WPF Resource Dictionary XSLT

To use images in wpf you can define:

<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" />
</
开发者_如何学运维

Then in app somewhere you can:

var img = (ImageSource)positionsTab.TryFindResource("ImageFunTime");

How can I achieve the same thing with an embedded Xslt file? That is, whats the syntax in the resource dictionary, as its obviously not an Bitmap image...

TIA


How can I achieve the same thing with an embedded Xslt file?

Answers:

  1. None of the Microsoft's XSLT processor supports embedded XSLT stylesheets. You will need a complete, XSLT-only file for your XSLT stylesheet.

  2. In XSLT one uses the <xsl:key> instruction and the key() function for efficient selecting nodes by some string value, that identifies them uniquely.

This transformation:

<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>

when applied on this XML document:

<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>

produces the wanted result:

../Resources/Images/ImageFunTime.png
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜