haq*_*win 13 .net silverlight silverlight-3.0 windows-phone-7
我有银色问题我用了两天时间来打架:带有样式的模板控制按钮.在具体按钮中,我有一个以路径为内容的画布.问题是我希望路径填充颜色从模板中的ContentControl绑定到Foreground.
但是,我还没弄清楚如何构造绑定以获取Forground.如果我愿意,例如使用TextBlock,它将自动从Style中获取Forground颜色.正如预期的那样,文本具有前景色.绑定的原因是动画控制着forground,我希望它传播到路径的填充颜色.有任何想法吗?
该模板包含以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
在我的布局中,我有以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
我已经清理了代码并删除了一些内容以使其更具可读性,但我希望你能够了解它背后的想法.
由于您为按钮指定了名称,因此可以使用Binding ElementName参数:
<Button x:Name="Play" Style="{StaticResource PathButtonStyle}" >
<Canvas x:Name="PlayIcon">
<Path Data="F1M191.4839,96.1763L177.9149,106.5173L177.9149,85.9293z"
Fill="{Binding Foreground, ElementName=Play}" />
</Canvas>
</Button>
Run Code Online (Sandbox Code Playgroud)