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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
async Task MethodAsync(Storyboard sb, int delay)
{
sb.Begin(this);
await Task.Delay(TimeSpan.FromSeconds(delay));
}
private async void anim_grid()
{
// Grid Externe avec une balise <Grid x:Name="Mother"> est dans le code xaml
Grid grid1 = GetGrid1_Test();
Grid grid2 = GetGrid2_Test();
Canvas C1 = new Canvas();
C1.Background = Brushes.Blue;
Mother.Children.Add(grid1);
Load_data(grid2,0, 0);
C1.Children.Add(grid2);
Grid.SetRow(C1, 1);
Grid.SetColumn(C1, 5);
grid1.Children.Add(C1);
// animation
Storyboard myStoryboard = new Storyboard();
///animation deplacement y
TranslateTransform myTranslateTransformy = new TranslateTransform();
C1.RenderTransform = myTranslateTransformy;
this.RegisterName("MyAnimatedTransformy", myTranslateTransformy);
DoubleAnimation myDoubleAnimationy = new DoubleAnimation();
myDoubleAnimationy.From = +1200; //from hors de l'écran
myDoubleAnimationy.To = 0;
myDoubleAnimationy.Duration = new Duration(TimeSpan.FromSeconds(2));
myDoubleAnimationy.AutoReverse = false;
Storyboard.SetTargetName(myDoubleAnimationy, "MyAnimatedTransformy");
Storyboard.SetTargetProperty(myDoubleAnimationy, new PropertyPath(TranslateTransform.YProperty));
myStoryboard.Children.Add(myDoubleAnimationy);
Task tache = MethodAsync(myStoryboard, 2);
await tache;
//nouvelle affectation du Canvas dans la Grille de Fond
Grid.SetRow(C1, 5);
Grid.SetColumn(C1, 5);
if (tache.IsCompleted)
{
Storyboard myStoryboard2 = new Storyboard();
//nouvelle translation
TranslateTransform myTranslateTransformy2 = new TranslateTransform();
C1.RenderTransform = myTranslateTransformy;
this.RegisterName("MyAnimatedTransformy2", myTranslateTransformy);
DoubleAnimation myDoubleAnimationy2 = new DoubleAnimation();
myDoubleAnimationy2.From = myDoubleAnimationy.To; //affectation de l'ancienne valeur de destination
myDoubleAnimationy2.To = 0;
myDoubleAnimationy2.Duration = new Duration(TimeSpan.FromSeconds(3));
myDoubleAnimationy2.AutoReverse = false;
Storyboard.SetTargetName(myDoubleAnimationy2, "MyAnimatedTransformy2");
Storyboard.SetTargetProperty(myDoubleAnimationy2, new PropertyPath(TranslateTransform.YProperty));
myStoryboard2.Children.Add(myDoubleAnimationy2);
Task tache2 = MethodAsync(myStoryboard2, 4);
await tache2;
if (tache2.IsCompleted)
{
//etc...
}
}
}
private void Load_data(Grid grid2,int row,int col)
{
TextBox nom = new TextBox();
TextBox prenom = new TextBox();
nom.Text = "DUPONT";
prenom.Text = "Albert";
Grid.SetRow(nom, row);
Grid.SetColumn(nom, col);
grid2.Children.Add(nom);
Grid.SetRow(prenom, row+1);
Grid.SetColumn(prenom,col);
grid2.Children.Add(prenom);
}
private Grid GetGrid1_Test()
{
Grid grd = new Grid();
grd.Name = "gridExterne";
grd.ShowGridLines = true;
for (int i = 0; i <= 9; i++)
{
RowDefinition rowdef = new RowDefinition();
rowdef.Height = new GridLength(10, GridUnitType.Star);
grd.RowDefinitions.Add(rowdef);
}
for (int i = 0; i <= 9; i++)
{
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = new GridLength(10, GridUnitType.Star);
grd.ColumnDefinitions.Add(coldef);
}
return grd;
}
private Grid GetGrid2_Test()
{
Grid grd = new Grid();
grd.Name = "gridInterne";
grd.ShowGridLines = true;
for (int i = 0; i <= 2; i++)
{
RowDefinition rowdef = new RowDefinition();
rowdef.Height = new GridLength(10, GridUnitType.Star);
grd.RowDefinitions.Add(rowdef);
}
for (int i = 0; i <= 2; i++)
{
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = new GridLength(10, GridUnitType.Star);
grd.ColumnDefinitions.Add(coldef);
}
return grd;
} |
Partager