 <pre><code>&lt;Button&gt; &lt;Button.Background&gt; &lt;ImageBrush Source="/AlarmClock;component/Images/page_preview.png" /&gt; &lt;/Button.Background&gt; &lt;/Button&gt; </code></pre> <p>just make sure the file is maked as "Resource" in visual studio. Alternatively you can mark it as "Content" and use it like this:</p> <pre><code> &lt;ImageBrush Source="/Images/page_preview.png" /&gt; </code></pre> <p>I don't know if you need to assign the background programatically (because you can do it in markup), but if you do here is what you need to say:</p> <pre><code>viewButton.Background = new ImageBrush { Source = new BitmapImage(new Uri("", UriKind.Relative)) } </code></pre> <p>[FURTHER]</p> <p>in order set margin programmatically:</p> <pre><code>viewButton.Margin = new Thickness(left, top, right, bottom); </code></pre>