Jump to content
СофтФорум - всё о компьютерах и не только

Одинаковая скорость при выполнении анимации


Recommended Posts

Всем привет.
Можете подсказать, как сделать чтобы скорость объектов при выполнении анимации была одинаковой?

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>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...