2

アニメーションに関連する 2 つの問題があります。

1) 次のコードはタイトルとボーダーをアニメーション化しません。私は this.FadeIn() のように次のように呼び出しています。これはもちろん UIElement 型です。

public static void FadeIn(this UIElement targetControl)
    {
        DoubleAnimation fadeInAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1.5)));
        Storyboard.SetTarget(fadeInAnimation, targetControl);
        Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
        Storyboard sb = new Storyboard();
        sb.Children.Add(fadeInAnimation);
        sb.Begin();
    }

2) これも機能せず、アニメーションが表示されません。

public static void SkewAnimation(this UIElement targetControl) 
{ 
   DoubleAnimation skewAnimation = new DoubleAnimation(0, 360, new    Duration(TimeSpan.FromSeconds(3)));
   Storyboard.SetTarget(skewAnimation, targetControl);

   Storyboard.SetTargetProperty(skewAnimation, new  PropertyPath(SkewTransform.AngleXProperty)); 
   Storyboard sb = new Storyboard();
   sb.Children.Add(skewAnimation);
   sb.Begin(); 
}
4

1 に答える 1

6

次のように単純にアニメーション化してみませんか。

public static void FadeIn(this UIElement element)
{
    element.BeginAnimation(
        UIElement.OpacityProperty,
        new DoubleAnimation(0d, 1d, TimeSpan.FromSeconds(1.5)));
}

また、要素のRenderTransformプロパティが SkewTransform に設定されている場合:

public static void SkewAnimation(this UIElement element)
{
    ((SkewTransform)element.RenderTransform).BeginAnimation(
        SkewTransform.AngleXProperty,
        new DoubleAnimation(0d, 360d, TimeSpan.FromSeconds(3d)));
}

編集:これには次のようなものが必要です

element.RenderTransform = new SkewTransform();

または XAML で:

<SomeElement>
    <SomeElement.RenderTransform>
        <SkewTransform />
    </SomeElement.RenderTransform>
</SomeElement>

FadeIn が機能しない理由はわかりませんが、プロパティ パスが原因で SkewAnimation が機能しません。SkewTransform.AngleXPropertyUIElement には定義されていません。プロパティ パスは次のようにする必要があります (RenderTransform が SkewTransform に設定されている場合)。

new PropertyPath("RenderTransform.(SkewTransform.AngleXProperty)");
于 2012-08-09T17:08:03.827 に答える