0

スタックパネルの可視性が可視状態に設定されているときにサイズ変更アニメーションが必要ですが、その代わりに、スタックパネルを含む境界線が際限なくちらつきます。間違っているとは思いません。スタック パネルには、TextBlock のインスタンスが含まれています。

private void MyBorder_SizeChanged_1(object sender, SizeChangedEventArgs e)
{
    if (!first)
    {
        DoubleAnimation anim = new DoubleAnimation();
        anim.From = e.PreviousSize.Height;
        anim.To = e.NewSize.Height;
        anim.Duration = new Duration(TimeSpan.FromSeconds(1));
        Storyboard.SetTarget(anim, MyBorder);
        Storyboard.SetTargetProperty(anim, new PropertyPath(Border.HeightProperty));
        Storyboard st = new Storyboard();
        st.Children.Add(anim);
        st.Begin();
    }
    first = false;
}

private void MyBorder_Tap_1(object sender, GestureEventArgs e)
{
    if (MyPanel.Visibility == Visibility.Collapsed)
        MyPanel.Visibility = Visibility.Visible;
    else
        MyPanel.Visibility = Visibility.Collapsed;
}
4

3 に答える 3

0

問題は、境界線の高さをアニメーション化すると SizeChanged イベントがトリガーされるため、サイズ変更イベント>高さのアニメーション>サイズ変更イベント> ..
また、サイズ変更イベントが発生すると、サイズ変更が発生することですすでに配置されているため、それが機能していたとしても、アニメーションを実行するために戻ったときに少しフリックします。
最後に、アニメーションで HEight を使用すると、レンダリングの更新が強制されるため、ハードウェア アクセラレーションは行われません。おそらく、Translate Transform または Scale Transform を実行するのが最善でしょう。
たとえば、タップ イベントで MyPanel で直接 0 と 1 の間のスケール変換を行うことができます。

于 2013-09-15T20:34:07.483 に答える
0

私はこの問題を解決しました。愚かなことに、私は StackPanel の Measure メソッドが非公開であると考え、それについて確認することを気にしませんでした。クリック時に StackPanel を展開するためのソリューション コードを次に示します。

private void MyBorder_Tap_1(object sender, GestureEventArgs e)
{
    if (MyPanel.Visibility == Visibility.Collapsed)
    {
        MyPanel.Visibility = Visibility.Visible;
        MyPanel.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
        DoubleAnimation anim = new DoubleAnimation();
        anim.From = MyBorder.ActualHeight;
        anim.To = MyBorder.ActualHeight + MyPanel.DesiredSize.Height;
        anim.Duration = new Duration(TimeSpan.FromSeconds(0.25));
        Storyboard.SetTarget(anim, MyBorder);
        Storyboard.SetTargetProperty(anim, new PropertyPath(Border.HeightProperty));
        Storyboard st = new Storyboard();
        st.Children.Add(anim);
        st.Begin();
    }
    else
    {
        MyPanel.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
        DoubleAnimation anim = new DoubleAnimation();
        anim.From = MyBorder.ActualHeight;
        anim.To = MyBorder.ActualHeight - MyPanel.DesiredSize.Height;
        anim.Duration = new Duration(TimeSpan.FromSeconds(0.25));
        Storyboard.SetTarget(anim, MyBorder);
        Storyboard.SetTargetProperty(anim, new PropertyPath(Border.HeightProperty));
        Storyboard st = new Storyboard();
        st.Children.Add(anim);
        st.Completed += (a,b) => { MyPanel.Visibility = Visibility.Collapsed; };
        st.Begin();
    }
}

于 2013-09-16T19:08:20.903 に答える