title: WPF Image source from constant
body: <p>I've got some icons that are resources in my project and I plan to use these icons for menu items and other things.</p>
  
  <p>I've created a constants class to hold the locations of these icons in a central location rather than hardcoding them into each menu item etc.</p>
  
  <p>E.g.</p>
  
  <pre><code>public const string IconName = "/Project;component/Icons/IconName.png";
  </code></pre>
  
  <p>If I hardcode this value into the Source property of an image in xaml it works fine. However, if I try to reference this constant then it fails.</p>
  
  <p>E.g.</p>
  
  <pre><code>&lt;Image Source="{x:Static pb:IconConstants.IconName}" Width="16" Height="16" /&gt;
  </code></pre>
  
  <p>It fails with this exception: "Cannot convert the value in attribute 'Source' to object of type 'System.Windows.Media.ImageSource'. ".</p>
  
  <p>What is the difference between this and me just hardcoding the value? Is there a better way of referencing my constants in xaml?</p>
  
  <p>Thanks,
  Alan</p>