나는 다음과 같은 WPF 창 있습니다 뒤에 다음 코드와DoubleAnimation에서 사용자 지정 종속성 속성이 애니메이션으로 적용되지 않는 이유는 무엇입니까?
<Window x:Class="AnimationTest.MainWindow"
x:Name="main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" >
<Window.Resources>
<Storyboard RepeatBehavior="Forever" x:Key="animationStoryboard" TargetName="main" TargetProperty="CurrentOffset" >
<DoubleAnimation From="0" To="100" Duration="0:0:5" SpeedRatio=".8" AutoReverse="True" />
</Storyboard>
</Window.Resources>
<Grid>
</Grid>
</Window>
을 :
using System.Windows;
using System.Windows.Media.Animation;
namespace AnimationTest
{
public partial class MainWindow : Window
{
public static DependencyProperty CurrentOffsetProperty = DependencyProperty.Register("CurrentOffset", typeof(double), typeof(MainWindow), new FrameworkPropertyMetadata(OnCurrentOffsetPropertyChanged));
private static void OnCurrentOffsetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MainWindow control = (MainWindow)d;
}
public double CurrentOffset
{
get
{
return (double)base.GetValue(MainWindow.CurrentOffsetProperty);
}
set
{
MessageBox.Show("Hit");
base.SetValue(MainWindow.CurrentOffsetProperty, value);
}
}
public MainWindow()
{
InitializeComponent();
((Storyboard)base.FindResource("animationStoryboard")).Begin(this);
}
}
}
은 내가 CurrentOffset 속성 continuosly라고하지만 아무 일도 발생하지 않습니다이 예상. 애니메이션이 시작되지 않는 것과 같습니다. 누구나 내가 잘못 알았어?
미리 감사드립니다.
잘 AFAIK DP에 대한 파일의 속성 정의가 프레임 워크에 의해 호출되지 않으며 코드 뒤에서 DP에 액세스 할 때만 도우미 역할을합니다. 따라서 MessageBox.Show()는 애니메이션이 잘 돌아 갔음에도 불구하고 기본 WPF 시스템에 의해 호출되지 않습니다. 애니메이션 저장이 저장된 값을 확인한 후에 DP 값을 확인해 보았습니까? – Viv
Viv의 설명에 대한 설명은 [이 기사] (http://msdn.microsoft.com/en-us/library/bb613563.aspx)를 참조하십시오. ('MessageBox.Show()'호출을 OnCurrentOffsetPropertyChanged '메소드를 사용하여 애니메이션이 작동하는지 확인하십시오). – Clemens