Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a XAML Image as a WPF Window background
    text
    copied!<p>Any suggestions how to go about having a XAML vector image as a Window background? There's plenty of code showing this with jpg's but I'd prefer a vector based image.</p> <p>Having it as a resource would be a bonus too but I'm stumped as to the best approach.</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Viewbox x:Key="Background2" Stretch="Fill"&gt; &lt;Canvas &gt; &lt;!-- Ebene 1/&lt;Path&gt; --&gt; &lt;Path Fill="#ff000000" Data="F1 M 841.890,595.275 L 0.000,595.275 L 0.000,0.000 L 841.890,0.000 L 841.890,595.275 Z"/&gt; &lt;!-- Ebene 1/&lt;Path&gt; --&gt; &lt;Path Data="F1 M 265.910,218.277 C 265.910,169.332 223.865,129.655 172.000,129.655 C 120.135,129.655 78.090,169.332 78.090,218.277 C 78.090,267.222 120.135,306.898 172.000,306.898 C 223.865,306.898 265.910,267.222 265.910,218.277 Z"&gt; &lt;Path.Fill&gt; &lt;RadialGradientBrush MappingMode="Absolute" GradientOrigin="172.733,217.234" Center="172.733,217.234" RadiusX="81.912" RadiusY="81.912"&gt; &lt;RadialGradientBrush.GradientStops&gt; &lt;GradientStop Offset="0.00" Color="#ff0d4976"/&gt; &lt;GradientStop Offset="0.41" Color="#ff06243b"/&gt; &lt;GradientStop Offset="1.00" Color="#ff000000"/&gt; &lt;/RadialGradientBrush.GradientStops&gt; &lt;RadialGradientBrush.Transform&gt; &lt;MatrixTransform Matrix="1.146,0.000,0.000,1.082,-26.038,-16.750" /&gt; &lt;/RadialGradientBrush.Transform&gt; &lt;/RadialGradientBrush&gt; &lt;/Path.Fill&gt; &lt;/Path&gt; &lt;/Canvas&gt; &lt;/Viewbox&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>The Resource code above works fine if you remove the Viewbox. The code for the window is :-</p> <pre><code> &lt;Window x:Class="Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window2" Height="700" Width="800"&gt; &lt;Window.Resources&gt; &lt;ResourceDictionary Source="Resources/Dictionary2.xaml" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;StaticResource ResourceKey="Background2"/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload