我有一个动画到值集的条形图。动画代码看起来像
<UserControl.Resources>
<Storyboard x:Key="BootUp">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="MainBar">
<EasingDoubleKeyFrame KeyTime="0" Value="350"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="{Binding CurrentValue, ElementName=UserControl}"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
和 C#
int ThisValue=200;
public int CurrentValue
{
get { return (int)ThisValue; }
set {
ThisValue=(int)value;
this.MainBar.ToolTip=value.ToString();
System.Windows.Media.Animation.Storyboard storyBoard = (System.Windows.Media.Animation.Storyboard)FindResource("BootUp");
storyBoard.Begin(this);
}
}
我认为这应该有效,但每次它返回
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=UserControl'. BindingExpression:Path=CurrentValue; DataItem=null; target element is 'EasingDoubleKeyFrame' (HashCode=27594380); target property is 'Value' (type 'Double')
到底是怎么回事?