在样式从ContentControl中前景属性的路径填充属性绑定 [英] Bind a fill property in a path to a Foreground property from the ContentControl in a style

查看:166
本文介绍了在样式从ContentControl中前景属性的路径填充属性绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Silverlight的问题,我心中已经用两天打:与风格模板控制按钮。在具体的按钮,我有作为内容路径画布。问题是,我想要的路径填充颜色绑定到前景从ContentControl中在模板中。

I have silverlight problem I'v used two days to fight: a template with a style controls a button. In the concrete button I have a canvas with paths as content. The problem is that I want the paths fill color to bind to the Foreground from the ContentControl in the template.

不过,我一直无法弄清楚如何构建结合到于地面。如果我想,例如使用一个TextBlock,它会自动从样式于地面的颜色。正如预期的文本具有一个前景色。究其原因,绑定是动画控制于地面,我希望它传播到路径的填充颜色。任何想法?

However, I haven't been able to figure out how to construct the binding to get to the Forground. If I would, for example use a TextBlock, it will automatically get the Forground color from the Style. As expected as the text has a Foreground color. The reason for the binding is that the animation controls the forground and I want it to propagate to the fill color of the path. Any Ideas?

该模板包含以下内容:

<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>

下来在我的布局我有以下几点:

Down in my Layout I have the following:

<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>

我cleand了code和删除的东西,使其更具可读性,但我希望你得到它背后的想法。

I've cleand up the code and removed stuff to make it more readable, but I hope you get the idea behind it.

推荐答案

既然你给了一个名称为您的按钮,您可以使用绑定的ElementName 参数:

Since you gave a name to your button, you can use the Binding ElementName parameter:

<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>

这篇关于在样式从ContentControl中前景属性的路径填充属性绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆