Пятница, 15 Ноября 2024, 05:00

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Одинаковая скорость при выполнении анимации
Slant-shadowДата: Пятница, 30 Января 2015, 21:43 | Сообщение # 1
был не раз
Сейчас нет на сайте
Всем привет.
Можете подсказать, как сделать чтобы скорость объектов при выполнении анимации была одинаковой?

Код
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
   
namespace WpfApplication2
{
     /// <summary>
     /// Interaction logic for MainWindow.xaml
     /// </summary>
     public partial class MainWindow : Window
     {
         public MainWindow()
         {
             InitializeComponent();
             ta.Completed += ComplitedAnimation;
   
             ta.FillBehavior = FillBehavior.Stop;
             ta.Duration = TimeSpan.FromSeconds(0.5);
             ta.Duration = new Duration(new TimeSpan(0, 0, 5));
         }
   
         ThicknessAnimation ta = new ThicknessAnimation();
   
         public double main_window_width { get { return main_window_grid.ActualWidth; } }
         public bool fl1;
         public bool fl2;
         private Thickness marginBackup;
   
         private void ComplitedAnimation(object sender, EventArgs e)
         {            
             if (fl1 == true)
             {
                 fl1 = false;
                 grid_blue.Visibility = Visibility.Visible;
                 grid_red.Margin = marginBackup;
             }
   
             if (fl2 == true)
             {
                 fl2 = false;
                 grid_red.Visibility = Visibility.Collapsed;
                 grid_blue.Margin = marginBackup;
             }
   
         }
   
         private void Move_Animation(object sender, RoutedEventArgs e)
         {
             fl1 = true;
             ta.From = new Thickness(main_window_width, 0, 0, 0);
             ta.To =  grid_red.Margin;
             marginBackup =  grid_red.Margin;
            
             grid_red.BeginAnimation(MarginProperty, ta);
             grid_red.Visibility = Visibility.Visible;
   
             ta.From = grid_blue.Margin;
             ta.To = new Thickness(0, 0, main_window_width, 0);
             grid_blue.BeginAnimation(MarginProperty, ta);
         }
     }
}


Код
<Window x:Class="WpfApplication2.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Title="MainWindow" Height="350" Width="525">
     <Grid x:Name="main_window_grid">
         <Grid>
             <Grid x:Name="grid_blue"  Height="200" Width="350" Background="Blue" Margin="0,0,0,0">
             <Button Name="bt_blue" Width="50" Height="50" Margin="200,100,0,0" Content="button" Click="Move_Animation"></Button>
         </Grid>
         <Grid x:Name="grid_red"  Height="200" Width="350" Background="red" Margin="0,0,0,0" Visibility="Collapsed">
                 <Button Name="bt_red" Width="50" Height="50" Margin="200,100,0,0" Content="button"></Button>
         </Grid>
         </Grid>
     </Grid>
</Window>
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг