简体   繁体   English

自定义控件情节提要板模板绑定不起作用-XAML C#

[英]Custom Control Storyboard Template Binding Not Working - XAML C#

I created a custom Control which has some Dependency Properties which values I also Need to assign to the storyboard in the ControlTemplate. 我创建了一个自定义控件,该控件具有一些依赖项属性,我还需要将这些属性值分配给ControlTemplate中的情节提要。

Here is the beginning of the Code of my Control Template : 这是我的Control Template代码的开头:

 <ControlTemplate TargetType="local:RingPresenter">
                <Grid x:Name="RootGrid">
                    <Grid.Resources>
                        <Storyboard x:Key="StatisticUpdateAnnimation">
                            <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(RingSlice.EndAngle)" Storyboard.TargetName="ringSlice">
                                <EasingDoubleKeyFrame KeyTime="0" Value="45"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="{TemplateBinding Angle}">

The Important part is the Value={TemplateBinding Angle}" - the value is getting applied succesfully to my 重要部分是Value={TemplateBinding Angle}" -该值已成功应用于我的

 <helper:RingSlice InnerRadius="100" Radius="150"  StartAngle="0" EndAngle="{TemplateBinding Angle}"  Fill="DarkCyan" x:Name="ringSlice">
                        </helper:RingSlice>

... which is part of my Control Template , but in the storyboard the value is staying 0. The Debugger is saying that Angle has the correct value and it is working fine for my Ringslice and even the metadata should be 45. ... 这是我的控制模板的一部分 ,但在情节提要中该值保持为0。调试器说Angle具有正确的值,并且对我的Ringslice正常工作,甚至元数据也应为45。

Why is this value not applied to my storyboard? 为什么此值不适用于我的故事板? How can I fix this? 我怎样才能解决这个问题?

When in doubt, swap EndAngle="{TemplateBinding Angle}" for EndAngle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Angle}" . 如有疑问, EndAngle="{TemplateBinding Angle}"换为EndAngle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Angle}"

TemplateBinding is quick and useful but doesn't always have the strongest capacity to feed through information it's bound to, for reasons that escape me entirely. TemplateBinding既快速又有用,但并非总是具有最强的能力来传递其绑定的信息,原因完全使我无法逃避。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM