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:
<Grid>
<Rectangle x:Name="ImageForeground" Height="48" Width="48"
Fill="{StaticResource PhoneForegroundBrush}" >
<Rectangle.OpacityMask>
<ImageBrush Stretch="Fill" ImageSource="/icons/play.png"/>
</Rectangle.OpacityMask>
</Rectangle>
</Grid>
But as soon as I try template this with a DependencyProperty for the image lite this:
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(ImageSource),
typeof(RButton), null);
And then in the XAML like this:
<Grid>
<Rectangle x:Name="ImageForeground" Height="48" Width="48"
Fill="{TemplateBinding Foreground}" >
<Rectangle.OpacityMask>
<ImageBrush Stretch="Fill" ImageSource="{TemplateBinding Image}"/>
</Rectangle.OpacityMask>
</Rectangle>
</Grid>
I get an error saying:
object of type 'System.Windows.CustomDependencyProperty'
cannot be converted to type 'System.Windows.DependencyProperty'
The ImageProperty is ok, as I tested binding it to an image instead like this
<Image Source="{TemplateBinding Image}" Width="48" Height="48" />
Any ideas? My hunch says its in how I define my DependecyProperty, but I don't know how to move forward.