title: How to convert a ViewBox to an ImageSource?
body: <p>I'm using a <code>Viewbox</code> to create a set of icons that I will dynamically bind to a WPF view.</p>
  
  <p>I'm binding to the resource name and using a <code>Converter</code> to convert the resource name to an <code>ImageSource</code>.</p>
  
  <p>I know how to do it if the resource is a <code>Path</code>, but how to do it with a <code>Viewbox</code>?</p>
  
  <p>This is how I convert the resource name, if the resource is a <code>Path</code>, to an <code>ImageSource</code>:
  <pre><code>
  public class ResourceNameToImageSourceConverter : BaseValueConverter {
      protected override ImageSource Convert(string value, System.Globalization.CultureInfo culture) {
          var resource = new ResourceDictionary();
          resource.Source = new Uri("pack://application:,,,/MyAssembly;component/MyResourceFolder/ImageResources.xaml", UriKind.Absolute);
          var path = resource[value] as Path;
          if (path != null) {
              var geometry = path.Data;
              var geometryDrawing = new GeometryDrawing();
              geometryDrawing.Geometry = geometry;
              var drawingImage = new DrawingImage(geometryDrawing);</p>
  
  <pre><code>        geometryDrawing.Brush = path.Fill;
          geometryDrawing.Pen = new Pen();
  
          drawingImage.Freeze();
          return drawingImage;
      } else {
          return null;
      }
  }
  </code></pre>
  
  <p>}
  </pre>
  And this is what the Viewbox declaration looks like.</p>
  
  <pre>
  &lt;Viewbox&gt;
      &lt;Viewbox&gt;
        &lt;Grid&gt;
          &lt;Path&gt;
          ...
          &lt;/Path&gt;
          &lt;Path&gt;
          ...
          &lt;/Path&gt;
          &lt;Path&gt;
          ...
          &lt;/Path&gt;
          &lt;Rectangle&gt;
          ...
          &lt;/Rectangle&gt;
        &lt;/Grid&gt;
      &lt;/Viewbox&gt;
  &lt;/Viewbox&gt;
  </code></pre>