我有以下 WPF 窗口:
<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 属性,但没有任何反应。这就像动画不会开始。任何人都可以指出我错在哪里?
提前致谢。