使用DependencyProperty将ImageBrush绑定到模板

haq*_*win 2 silverlight xaml windows-phone-7

我正在尝试创建一个特殊按钮,根据系统中的Foreground颜色为图像着色.解决方案似乎是使用图像作为不透明蒙版来获取颜色,当我像这样直接设置图像时它可以工作:

<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>
Run Code Online (Sandbox Code Playgroud)

但是,一旦我尝试使用DependencyProperty为图像精简模板这个:

public static readonly DependencyProperty ImageProperty  =
  DependencyProperty.Register("Image", typeof(ImageSource), 
                              typeof(RButton), null);  
Run Code Online (Sandbox Code Playgroud)

然后在XAML中这样:

<Grid>
  <Rectangle x:Name="ImageForeground" Height="48" Width="48" 
    Fill="{TemplateBinding Foreground}" >
    <Rectangle.OpacityMask>
      <ImageBrush Stretch="Fill" ImageSource="{TemplateBinding Image}"/>
    </Rectangle.OpacityMask>
  </Rectangle>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说:

object of type 'System.Windows.CustomDependencyProperty' 
  cannot be converted to type 'System.Windows.DependencyProperty'
Run Code Online (Sandbox Code Playgroud)

ImageProperty没问题,因为我测试将它绑定到图像而不是像这样

<Image Source="{TemplateBinding Image}" Width="48" Height="48" />
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我的预感是如何定​​义我的DependecyProperty,但我不知道如何前进.

Bor*_*ska 6

图像刷不自FrameworkElement继承,因此它不能被TemplateBound或数据绑定.