2012-11-14 3 views
0

필자는 값 집합으로 움직이는 막 대형 차트를 사용합니다. 애니메이션 코드는WPF 키 프레임 바인딩

<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') 

을 반환?

+0

당신의 UserControl 이름의 UserControl이 있습니까 :이 ..with

Value="{Binding CurrentValue, ElementName=UserControl}" 

:

이 교체

? –

+0

예, BarItem 및 막대 항목에 대한 참조로 변경하려고 시도했지만 여전히 작동하지 않습니다. – Bonzo

답변

2

바인딩이 UserControl을 찾는 방식을 변경하면 제대로 작동합니다.

Value="{Binding CurrentValue, RelativeSource={RelativeSource AncestorType=UserControl}} 
+1

왜 이것이 작동해야한다고 생각하니, OP가 어떻게 이것을 받아들 였는지, 애니메이션이 정지 가능한 객체인지, 속성이 바뀌지는 않을지 [읽기] (https://msdn.microsoft.com/ ko-kr/library/ms750509.aspx) – AymenDaoudi