문제

나는 수업에서 사용자 정의 DP를 대상으로하는 int32animation이있는 매우 간단한 스토리 보드를 가지고 있습니다.

DP에 대한 콜백이 있습니다. 이는 Console.WriteLine ( "Current Value :" + MYDP)을 수행합니다.

스토리 보드를 실행하면 콘솔 출력이 잘 보일 수 있으며 스토리 보드를 일시 중지하면 콘솔 출력이 중지되지만 스토리 보드를 재개하면 DP가 다음 값이 아닙니다. 스토리 보드가 멈추었음에도 불구하고 계속 증가합니다.

이런 일이 그들에게 일어난 사람이 있습니까?

다음은 내가하는 일에 대한 코드 스 니펫입니다

            Int32Animation element = new Int32Animation();
            element.From = 0;
            element.To = targetTo;
            element.Duration = dur;
            Storyboard.SetTargetProperty(element, new PropertyPath(CurrentFrameProperty));
            _filmstripStoryboard = new Storyboard {SpeedRatio = this.FrameRate};
            _filmstripStoryboard.Children.Add(element);


        public void Start()
        {
            _filmstripStoryboard.Begin(this, true);
        }

        public void Pause()
        {
            _filmstripStoryboard.Pause(this);
        }

        public void Unpause()
        {
            _filmstripStoryboard.Resume(this);
        }
도움이 되었습니까?

해결책

거기에 MSDN 포럼에서 실 여기서 Microsoft는이 동작 (스토리 보드가 잠시 멈추는 경우에도 현재 값이 계속되고 있음)이 WPF의 당시 전류 (2006 년 기준)의 버그임을 확인합니다. 포럼 스레드에는 제안 된 해결 방법, 특히 일시 중지 할 때 현재 위치를 저장하고 재개 할 때 동일한 위치를 수동으로 찾습니다.

이 스레드는 향후 버전에서 버그를 고정하려는 생각을하고 있다고 언급했지만 .NET 3.5 또는 4.0이 실제로이 버그를 수정했는지 여부는 모르겠습니다.

편집하다: 버그는 .NET 4.0에서 고정 된 것으로 보입니다. 잠시 멈추고 개입 시간을 가로 질러 뛰어 내리지 않고 애니메이션을 재개 할 수있었습니다. (나는 3.5에서 테스트하지 않았다.)

다른 팁

이제 4.0에는 버그가 없습니다. 아래 코드는 잘 작동합니다.

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfAnimation.Win1805787"
    xmlns:Local="clr-namespace:WpfAnimation"
    x:Name="MyWindow"
    Title="Win1805787"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot">      

        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBox HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Text="{Binding CurrentFrame, ElementName=MyWindow}" Height="20" Margin="5,0,5,5"/>
            <Button x:Name="Play1" Content="Play" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Play_Click" Margin="5,0,5,5"/>
            <Button x:Name="Pause1" Content="Pause" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Click="Pause_Click" Margin="5,0,5,5"/>
            <Button x:Name="Resume1" Content="Resume" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Click="Resume_Click" Margin="5,0,5,5"/>
        </StackPanel>

        </Grid>

</Window>   

/////////////////////////

 using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using System.Windows.Media.Animation;

    namespace WpfAnimation
    {
        /// <summary>
        /// Interaction logic for Win1805787.xaml
        /// </summary>
        public partial class Win1805787 : Window
        {
            public Win1805787()
            {
                this.InitializeComponent();

                _createStoryBoard();
                // Insert code required on object creation below this point.
            }

            public int CurrentFrame
            {
                get { return (int)GetValue(CurrentFrameProperty); }
                set { SetValue(CurrentFrameProperty, value); }
            }

            // Using a DependencyProperty as the backing store for CurrentFrame.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty CurrentFrameProperty =
                DependencyProperty.Register("CurrentFrame", typeof(int), typeof(Win1805787), 
                        new PropertyMetadata(0, new PropertyChangedCallback(OnValueChanged)));

            private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {

            }

            Storyboard _filmstripStoryboard;

            void _createStoryBoard()
            {       
                Int32Animation element = new Int32Animation();
                element.From = 0;
                element.To = 100;
                element.Duration = Duration.Plus(new Duration(new TimeSpan(1000000000)));
                Storyboard.SetTargetProperty(element, new PropertyPath(CurrentFrameProperty));
                _filmstripStoryboard = new Storyboard { SpeedRatio = 0.5 };
                _filmstripStoryboard.Children.Add(element);
            }

            private void Play_Click(object sender, System.Windows.RoutedEventArgs e)
            {
                _filmstripStoryboard.Begin(this, true);
            }

            private void Pause_Click(object sender, System.Windows.RoutedEventArgs e)
            {
                _filmstripStoryboard.Pause(this);
            }

            private void Resume_Click(object sender, System.Windows.RoutedEventArgs e)
            {
                _filmstripStoryboard.Resume(this);
            }

        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top