我遇到了一个Silverlight问题:我使用了两天的时间去解决:一个带有样式控件的模板来控制一个按钮。在具体的按钮中,我有一个包含路径的画布作为内容。问题是我想要将路径的填充颜色绑定到模板中的ContentControl的Foreground。
然而,我一直无法找到如何构建绑定以获取到Foreground的方法。例如,如果我使用TextBlock,它会自动从样式中获取Foreground颜色。这是预期的,因为文本具有Foreground颜色。绑定的原因是动画控制前景色,我希望它传播到路径的填充颜色。有任何想法吗?
模板包含以下内容:
<Style x:Key="PathButtonStyle" TargetType="Button">
... Animations and state stuff
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" >
<ContentControl x:Name="ContentContainer"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Foreground="{TemplateBinding Foreground}" />
</Border>
</Style>
在我的布局中,我有以下内容:
<Button x:Name="Play" Style="{StaticResource PathButtonStyle}" >
<Canvas x:Name="PlayIcon">
<Path Data="F1M191.4839,96.1763L177.9149,106.5173L177.9149,85.9293z"
Fill="{PATH TO CONTENTCONTROLS FOREGROUND}" />
</Canvas>
</Button>
我已经清理了代码并删除了一些东西以使其更易读,但我希望你能理解其中的思路。