title: How do you get the ImageSource or value from Background?
body: <p>I have a Canvas which has a set background using an ImageBrush and ImageSource in the XAML.</p>
  
  <p><code>&lt;ImageBrush ImageSource="/Assets/mainDiagram.jpg" /&gt;</code></p>
  
  <p>I'm wondering how I can get the ImageSource or values from the Background member on the Canvas object.</p>
  
  <p>Here is the code I'm working with:</p>
  
  <pre><code>// this is the resolution of the background source image
  private int[] BkgResXY
  {
      get
      {
           int[] bkgResXY = new int[2];
  
           bkgResXY[0] = (int)(double)this.Background.GetValue(Panel.MaxWidthProperty);
           bkgResXY[1] = (int)(double)this.Background.GetValue(Panel.MaxHeightProperty);
  
           return bkgResXY;
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I see there are multiple height properties on the Panel class, Background inherits from the Panel Class. Not sure which one would be the ImageSource resolution.</p>
  
  <p>EDIT:</p>
  
  <p>So I've gotten this far <code>(this.Background as ImageBrush).ImageSource</code> but I hit a road block because ImageSource doesn't contain the original height and width of the source image.</p>
  
  <p>EDIT:</p>
  
  <p>I did this to get the background image resolution:</p>
  
  <pre><code>bkgResXY[0] = ((this.Background as ImageBrush).ImageSource as BitmapSource).PixelWidth;
  bkgResXY[1] = ((this.Background as ImageBrush).ImageSource as BitmapSource).PixelHeight
  </code></pre>