CustomControl样式中ControlTemplate中的TemplateBinding

时间:2018-02-09 13:30:07

标签: c# wpf binding

我的CustomControl非常简单

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()
    {

    }
}

我想与我的控制的SpeedRatio和故事板的SpeedRatio结合,看起来它并不想要。我有例外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>

如果我删除了TemplateBinding,它的工作正常。

0 个答案:

没有答案