1

Silverlight アプリケーションを作成しました。画像を反転させたいので、コードビハインドからストーリーボードを作成しました。しかし、「ターゲット名 Imagename を解決できません」というエラーがスローされます。

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

どこが間違っているのですか?

4

1 に答える 1

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;
       }     

// 関数にこれら 2 行を追加すると機能します

 Storyboard.SetTarget(FlipFront, imgFront);
          Storyboard.SetTarget(FlipBack, imgBack);
于 2012-09-06T06:34:13.143 に答える