Анимация не Уокинг (ширина)
Здравствуйте, Все!
Пожалуйста, может кто-нибудь помочь быстро,я новичок в анимации, и образец не работает, хотя нет никаких ошибок или предупреждений!
большое спасибо, Вот код:
.цезий
// Demonstrates the From and To properties used together. // Create a NameScope for this page so that // Storyboards can be used. NameScope.SetNameScope(this, new NameScope()); Rectangle myRectangle = new Rectangle(); // Assign the Rectangle a name so that // it can be targeted by a Storyboard. this.RegisterName( "fromToAnimatedRectangle", myRectangle); myRectangle.Height = 10; myRectangle.Width = 100; myRectangle.HorizontalAlignment = HorizontalAlignment.Left; myRectangle.Fill = Brushes.Black; // Demonstrates the From and To properties used together. // Animates the rectangle's Width property from 50 to 300 over 10 seconds. DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.From = 50; myDoubleAnimation.To = 300; myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(10)); Storyboard.SetTargetName(myDoubleAnimation, "fromToAnimatedRectangle"); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); Storyboard myStoryboard = new Storyboard(); myStoryboard.Children.Add(myDoubleAnimation); // Use an anonymous event handler to begin the animation // when the rectangle is clicked. myRectangle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs args) { myStoryboard.Begin(myRectangle); };
</<pre lang="HTML">pre>
Ширина должна измениться с 50 до 300, но ничего не происходит. Большое спасибо!!!
Что я уже пробовал:
.код XAML
<!-- Demonstrates the From and To properties used together. --> <Rectangle Name="fromToAnimatedRectangle" Height="10" Width="100" HorizontalAlignment="Left" Fill="Black"> <Rectangle.Triggers> <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown"> <BeginStoryboard> <Storyboard> <!-- Demonstrates the From and To properties used together. Animates the rectangle's Width property from 50 to 300 over 10 seconds. --> <DoubleAnimation Storyboard.TargetName="fromToAnimatedRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:10" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Rectangle.Triggers> </Rectangle>