Note that there are some explanatory texts on larger screens.

plurals
  1. POBind an ImageBrush to a template with a DependencyProperty
    primarykey
    data
    text
    <p>I'm trying to create a special button that colors an image based on Foreground color from the system. The solution seems to be in using the image as opacity mask to get the color and it works when I set the image directly like this:</p> <pre><code>&lt;Grid&gt; &lt;Rectangle x:Name="ImageForeground" Height="48" Width="48" Fill="{StaticResource PhoneForegroundBrush}" &gt; &lt;Rectangle.OpacityMask&gt; &lt;ImageBrush Stretch="Fill" ImageSource="/icons/play.png"/&gt; &lt;/Rectangle.OpacityMask&gt; &lt;/Rectangle&gt; &lt;/Grid&gt; </code></pre> <p>But as soon as I try template this with a DependencyProperty for the image lite this:</p> <pre><code>public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(RButton), null); </code></pre> <p>And then in the XAML like this:</p> <pre><code>&lt;Grid&gt; &lt;Rectangle x:Name="ImageForeground" Height="48" Width="48" Fill="{TemplateBinding Foreground}" &gt; &lt;Rectangle.OpacityMask&gt; &lt;ImageBrush Stretch="Fill" ImageSource="{TemplateBinding Image}"/&gt; &lt;/Rectangle.OpacityMask&gt; &lt;/Rectangle&gt; &lt;/Grid&gt; </code></pre> <p>I get an error saying:</p> <pre><code>object of type 'System.Windows.CustomDependencyProperty' cannot be converted to type 'System.Windows.DependencyProperty' </code></pre> <p>The ImageProperty is ok, as I tested binding it to an image instead like this</p> <pre><code>&lt;Image Source="{TemplateBinding Image}" Width="48" Height="48" /&gt; </code></pre> <p>Any ideas? My hunch says its in how I define my DependecyProperty, but I don't know how to move forward.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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