I am trying to create a special button that colors an image based on the Foreground color from the system. Apparently, the solution is to use the image as an opacity mask to get the color, and it works when I set the image directly as follows:
<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 the template using DependencyProperty for the lite image, do the following:
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(ImageSource),
typeof(RButton), null);
And then in 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 message:
object of type 'System.Windows.CustomDependencyProperty'
cannot be converted to type 'System.Windows.DependencyProperty'
ImageProperty is fine as I tested image binding instead
<Image Source="{TemplateBinding Image}" Width="48" Height="48" />
Any ideas? My hunch is about how I define my DependecyProperty, but I don't know how to move forward.