Одинаковая скорость при выполнении анимации
#38867282
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
Всем привет.
Можете подсказать, как сделать чтобы скорость объектов при выполнении анимации была одинаковой?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74.
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);
}
}
}
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
<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>
|
|