<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Zen of Software Development : XAML</title><link>http://blogs.technet.com/robertev/archive/tags/XAML/default.aspx</link><description>Tags: XAML</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Shared Resources XAML Intellisense</title><link>http://blogs.technet.com/robertev/archive/2008/03/30/shared-resources-xaml-intellisense.aspx</link><pubDate>Sun, 30 Mar 2008 03:18:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3023513</guid><dc:creator>robertev</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.technet.com/robertev/comments/3023513.aspx</comments><wfw:commentRss>http://blogs.technet.com/robertev/commentrss.aspx?PostID=3023513</wfw:commentRss><description>&lt;P&gt;&lt;STRONG&gt;[ I'll provide a full solution download to anyone interested ]&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;Our &lt;/STRONG&gt;&lt;STRONG&gt;Goals were:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1) Use images in XAML syntax like this:&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#a31515 size=2&gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;Image&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt; Name&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;="imageSave"&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt; Height&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;="16"&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt; Width&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;="16"&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt; Source&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;="ui:Images.ico_save_16.png"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;2) Break on invalid image references at&amp;nbsp;&lt;U&gt;COMPILE&lt;/U&gt; - not at runtime.&lt;BR&gt;3) Automatically add new when new images are copied into project.&lt;BR&gt;4) Share resources within solution across projects.&lt;BR&gt;5) Get intellisense for images from different projects in the same solution where possible (currently only in the codebehind - but the xaml editor will eventually provide intellisense here too).&lt;BR&gt;6) VS 2008&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_________________________________________________________&lt;/P&gt;
&lt;P&gt;We created a separate "Resources" class library. In that class library we created an Images folder and&amp;nbsp;under that an "ico" and "png" folders with all our images. Not added to "Resources" or "settings" as these generate only internal strongly typed - you need public.&lt;/P&gt;
&lt;P&gt;Step 2:&lt;/P&gt;
&lt;P&gt;Inside that class library create a text template&amp;nbsp;- I called it Generator.tt. This text template will scan your directory of files and&amp;nbsp;output something like this (below). We have two sub properties "ico" and "png" for the same resource... but you don't have to have that complexity.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000 size=2&gt;
&lt;P&gt;// &amp;lt;auto-generated&amp;gt;&lt;BR&gt;&lt;/FONT&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Images&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;ico_user_16&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;BitmapFrame&lt;/FONT&gt;&lt;FONT size=2&gt; png&lt;BR&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;/FONT&gt;&lt;FONT size=2&gt; { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;ResourceLocator&lt;/FONT&gt;&lt;FONT size=2&gt;.GetImageSource(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"ico_user_16.png"&lt;/FONT&gt;&lt;FONT size=2&gt;); }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;}&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//end ico_user_16 &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;#endregion&lt;/P&gt;
&lt;P&gt;------------------------------------------&lt;/P&gt;
&lt;P&gt;The only really tricky part in creating the tt file was figuring out how to find the current directory to scan the project files... &lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;string icoPath = this.Host.ResolvePath(@"Images\ico");&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;Now you can add references to that "Resources" class library from any project in your solution and get static resources in your xaml files... and share them across projects. As you add new images to your resource library simply save your Generator.tt file to&amp;nbsp;re-generate your static resources.&lt;/P&gt;
&lt;P&gt;Enjoy!!!&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3023513" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/robertev/archive/tags/images/default.aspx">images</category><category domain="http://blogs.technet.com/robertev/archive/tags/Resources/default.aspx">Resources</category><category domain="http://blogs.technet.com/robertev/archive/tags/XAML/default.aspx">XAML</category></item></channel></rss>