0

I have a CustomControl really simple

public class LoadingIndicator : Control
{

    public double SpeedRatio
    {
        get { return (double)GetValue(SpeedRatioProperty); }
        set { SetValue(SpeedRatioProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SpeedRatio.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SpeedRatioProperty =
        DependencyProperty.Register("SpeedRatio", typeof(double), typeof(LoadingIndicator), new PropertyMetadata(1.0));

    static LoadingIndicator()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(LoadingIndicator), new FrameworkPropertyMetadata(typeof(LoadingIndicator)));
    }

    public LoadingIndicator()
    {

    }
}

I'd like to make a binding with the SpeedRatio of my control and the SpeedRatio of the storyboard and it's appear that it doesn't want. I have an exception System.Windows.Markup.XamlParseException

<Style TargetType="{x:Type local:LoadingIndicator}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:LoadingIndicator}">
                <ControlTemplate.Triggers>
                    <EventTrigger RoutedEvent="local:LoadingIndicator.Loaded">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard SpeedRatio="{TemplateBinding SpeedRatio}" RepeatBehavior="Forever" Duration="0:0:1.000">
                                    ...
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

If I remove the TemplateBinding it's works fine.

Quentin
  • 144
  • 8
  • 2
    Please read this: https://stackoverflow.com/questions/2186933/wpf-animation-binding-to-the-to-attribute-of-storyboard-animation – mm8 Feb 09 '18 at 13:32
  • 2
    If I read well what said the msdn from the link in the article, it's normal because _You can't use dynamic resource references or data binding expressions to set Storyboard or animation property values. That's because everything inside a ControlTemplate must be thread-safe, and the timing system must Freeze Storyboard_ – Quentin Feb 09 '18 at 13:41
  • 1
    Yes, you are right. – mm8 Feb 09 '18 at 13:42

0 Answers0