2012-09-05 2 views
1

나는 실버 라이트 어플리케이션을 만들었습니다. 이미지를 뒤집어서 코드 뒤에 스토리 보드를 만들었습니다. 그러나 오류 "대상 이름을 확인할 수 없습니다."이 표시됩니다.코드 뒤에서 실버 라이트로 이미지 바꾸기

Storyboard sbFlip = new Storyboard(); 
      sbFlip.Duration = new Duration(TimeSpan.FromSeconds(3)); 
      DoubleAnimationUsingKeyFrames FlipFront = new DoubleAnimationUsingKeyFrames(); 
      DoubleAnimationUsingKeyFrames FlipBack = new DoubleAnimationUsingKeyFrames(); 
      Storyboard.SetTargetName(FlipFront, strFrontSelectedValue); 
      Storyboard.SetTargetName(FlipBack, strBackSelectedValue); 
      Storyboard.SetTargetProperty(FlipFront, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)")); 
      Storyboard.SetTargetProperty(FlipBack, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)")); 
      SplineDoubleKeyFrame sFlipFront = new SplineDoubleKeyFrame(); 
      SplineDoubleKeyFrame sFlipBack = new SplineDoubleKeyFrame(); 
      sFlipFront.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); 
      sFlipFront.Value = 0; 
      sFlipBack.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); 
      sFlipBack.Value = 1; 
      FlipFront.KeyFrames.Add(sFlipFront); 
      FlipBack.KeyFrames.Add(sFlipBack); 
      sbFlip.Children.Add(FlipFront); 
      sbFlip.Children.Add(FlipBack); 
      sbFlip.AutoReverse = true;    
      sbFlip.Completed += new EventHandler(this.sbFlip_Completed);  
      sbFlip.Begin(); 

나는 어디가 잘못 될까요 ???

+0

1st. 어느 선에서 오류가 발생합니까? 2 위. XAML로 만듭니다. 코드 숨김에 쓰레기 만들기를 그만 두십시오! – MyKuLLSKI

+0

1. 마지막 줄에서이 오류가 발생했습니다. 2. 내가 스토리 보드를 n 개 필요로하기 때문에 xaml에서 그럴 수 없다. 그게 내가 codebehind로 옮겼습니다. –

+0

XAML에 n 개의 숫자를 사용할 수 있습니다. 코드에서 수행 할 수있는 작업은 모두 XAML에서 수행 할 수 있습니다. 스토리 보드가 UI 컨트롤 (Window, UserControl)에 있는지 확인하고'this'를 전달하십시오 ...'sbFlip.Begin (this);' – MyKuLLSKI

답변

1

와우가 대답을 얻었습니다. 문자열을 이미지로 변환하고 함수에 전달한 다음 대상에 추가하면 이미지가 뒤집 힙니다.

.cs 페이지 :

Storyboard sbFlip = new Storyboard(); 
      sbFlip.Duration = new Duration(TimeSpan.FromSeconds(3)); 
      DoubleAnimationUsingKeyFrames FlipFront = new DoubleAnimationUsingKeyFrames(); 
      DoubleAnimationUsingKeyFrames FlipBack = new DoubleAnimationUsingKeyFrames(); 
      Storyboard.SetTargetName(FlipFront, strFrontSelectedValue); 
      Storyboard.SetTargetName(FlipBack, strBackSelectedValue); 
      Storyboard.SetTarget(FlipFront, imgFront); 
      Storyboard.SetTarget(FlipBack, imgBack); 
      Storyboard.SetTargetProperty(FlipFront, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)")); 
      Storyboard.SetTargetProperty(FlipBack, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)")); 
      SplineDoubleKeyFrame sFlipFront = new SplineDoubleKeyFrame(); 
      SplineDoubleKeyFrame sFlipBack = new SplineDoubleKeyFrame(); 
      sFlipFront.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); 
      sFlipFront.Value = 0; 
      sFlipBack.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); 
      sFlipBack.Value = 1; 
      FlipFront.KeyFrames.Add(sFlipFront); 
      FlipBack.KeyFrames.Add(sFlipBack); 
      sbFlip.Children.Add(FlipFront); 
      sbFlip.Children.Add(FlipBack); 
      sbFlip.AutoReverse = true;    
      sbFlip.Completed += new EventHandler(this.sbFlip_Completed);  
      sbFlip.Begin(); 

// 문자열을 전달하고 // 기능

Image imgBack = FindControl<Image>((UIElement)Layout, typeof(Image), strSelectedimg); 

이미지 찾기 이미지로 찾아

public T FindControl<T>(UIElement parent, Type targetType, string ControlName) where T : FrameworkElement 
     { 

      if (parent == null) return null; 

      if (parent.GetType() == targetType && ((T)parent).Name == ControlName) 
      { 
       return (T)parent; 
      } 
      T result = null; 
      int count = VisualTreeHelper.GetChildrenCount(parent); 
      for (int i = 0; i < count; i++) 
      { 
       UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i); 

       if (FindControl<T>(child, targetType, ControlName) != null) 
       { 
        result = FindControl<T>(child, targetType, ControlName); 
        break; 
       } 
      } 
      return result; 
     }  

//이 두 줄을 추가 funciton 작품에서

Storyboard.SetTarget(FlipFront, imgFront); 
      Storyboard.SetTarget(FlipBack, imgBack); 
+0

코드 숨김에서 사용하기 좋은 .. –

관련 문제