Matthias Herrmann
Matthias Herrmann

Reputation: 2790

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.

Here is the beginning of the Code of my 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

 <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 Anglehas the correct value and it is working fine for my Ringslice and even the metadata should be 45.

Why is this value not applied to my storyboard? How can I fix this?

Upvotes: 0

Views: 334

Answers (1)

Logan
Logan

Reputation: 816

When in doubt, swap EndAngle="{TemplateBinding Angle}" for 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.

Upvotes: 0

Related Questions