IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Comment arreter une animation en code ?


Sujet :

Windows Presentation Foundation

  1. #1
    Membre à l'essai
    Inscrit en
    Janvier 2008
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 27
    Points : 24
    Points
    24
    Par défaut Comment arreter une animation en code ?
    Bonjour,

    J'utilise une animation pour faire varier une progressbar, car ne connaissant pas le temps d'exécution d'un de mes trhreads.

    Mais je ne sais pas comment arreter cette animation .

    Voila mon code :

    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
      Duration duration = new Duration(TimeSpan.FromSeconds(1));
      DoubleAnimation doubleanimation;
            public void StartProgressBar()
            {
                doubleanimation = new DoubleAnimation(100.0, duration);
                doubleanimation.RepeatBehavior = RepeatBehavior.Forever;
                progressBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
            }
            public void StopProgressBar()
            {
    //sa marche pas ca 
                doubleanimation.RepeatBehavior = new RepeatBehavior(0);
            }
    Merci

  2. #2
    Membre expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Points : 3 015
    Points
    3 015
    Par défaut
    La propriété IsIndeterminate de la progressBar peut peut-être te convenir

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
          progbar.IsIndeterminate = true;
    Tu l'as passes à True lors du traitement et False à la fin. Ca fait ton animation en quelque sorte non ?

  3. #3
    Membre à l'essai
    Inscrit en
    Janvier 2008
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 27
    Points : 24
    Points
    24
    Par défaut
    C'est pas tout a fait pareil, au niveau rendu l'animation simulait la progression de la progressbar, et repartait au début ensuite.

    Avec ta solution c'est une zone fixe qui se ballade de gauche a droite dans la progressBar !

    Mais bon ca va me convenir pour l'instant, vu que je n'arrive pas a arrêter cette animation.

    Merci

    A+

  4. #4
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Utilise un StoryBoard pour ton animation. Comme ca, tu pourras le mettre en pause, le stoper, le démarrer, etc....

    http://forums.microsoft.com/MSDN/Sho...49806&SiteID=1

  5. #5
    Membre à l'essai
    Inscrit en
    Janvier 2008
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 27
    Points : 24
    Points
    24
    Par défaut
    Merci thomas, je viens d'essayer ca fonctionne, par contre en XAML on est obligé de mettre un evenement déclencheur ?

    RoutedEvent="ProgressBar.Loaded"> il se déclenche au chargement de UserControl, on peu pas eviter cela ?

    Autrement

    StoryProgressBar.Begin(this, true);

    StoryProgressBar.Stop(this);

    Fonctionne


    <ProgressBar VerticalAlignment="Stretch" Grid.Row="4" Grid.ColumnSpan="4" x:Name="progressBar" >
    <ProgressBar.Background>
    <LinearGradientBrush EndPoint="0.444,0.129" StartPoint="0.444,-0.118">
    <GradientStop Color="#FF134E60" Offset="0"/>
    <GradientStop Color="#FFECF6F9" Offset="0.986"/>
    </LinearGradientBrush>
    </ProgressBar.Background>
    <ProgressBar.Triggers>
    <EventTrigger RoutedEvent="ProgressBar.Loaded">
    <BeginStoryboard>
    <Storyboard x:Name="StoryProgressBar">
    <DoubleAnimation
    RepeatBehavior="Forever"
    Storyboard.TargetName="progressBar"Storyboard.TargetProperty="Value"
    From="0" To="100" Duration="0:0:5"/>
    </Storyboard>
    </BeginStoryboard>
    </EventTrigger>
    </ProgressBar.Triggers>
    </ProgressBar>

  6. #6
    Membre expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Points : 3 015
    Points
    3 015
    Par défaut
    Tu peux définir ton StoryBoard dans les Ressource du usercontrol.

  7. #7
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Citation Envoyé par binoo Voir le message
    Tu peux définir ton StoryBoard dans les Ressource du usercontrol.
    +1: Ce qui te permet ensuite d'y accéder par le code et de le manipuler

  8. #8
    Membre à l'essai
    Inscrit en
    Janvier 2008
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 27
    Points : 24
    Points
    24
    Par défaut
    Merci a vous deux, c'est bon maintenant. Je n'avais pas encore mis d'animation dans ce premier projet WPF.

    Voila mon code pour mon User control qui gere mes traitements asynchrone (pour des appels WCF) et qui incopore un ProgresseBar et une liste de BackGroundWorker (multithread), pour ceux que ca intéresse.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Windows.Media.Animation;
    using System.ComponentModel;
    using System.Threading;
    using Entreprise.Relance.Client.ModelView;
    using Entreprise.Relance.Client.Model;
    namespace RelanceWPF
    {
    publicpartialclassUCProgressBar : UserControl
    {
    publicVistaWindow MaFenetre;
    privatestaticApp AppRelance = ((App)Application.Current);
    staticreadonlyobject verrou = newobject();
    Storyboard StoryProgressBar;
    Dictionary<int, BackgroundWorker> lstBgWorker = newDictionary<int, BackgroundWorker>();
    publicstaticApp MonApplication
    { 
    get
    {
    return AppRelance;
    }
    }
    public UCProgressBar()
    {
    InitializeComponent();
    StoryProgressBar = (Storyboard)this.FindResource("StoryProgressBar");
    }
     
    publicvoid StartProgressBar()
    {
    StoryProgressBar.Begin(this, true);
    }
    publicvoid StopProgressBar()
    {
    StoryProgressBar.Stop(this);
    }
    #region worker
    BackgroundWorker InitNewWorker()
    {
    BackgroundWorker worker = newBackgroundWorker();
    worker.DoWork += newDoWorkEventHandler(worker_Traitement);
    //worker.WorkerSupportsCancellation = true;
    worker.RunWorkerCompleted += newRunWorkerCompletedEventHandler(worker_Completed);
    }
    BackgroundWorker NewWorker()
    {
    BackgroundWorker worker = InitNewWorker();
    lock(verrou)
    {
    lstBgWorker.Add(worker.GetHashCode(), worker);
    StartProgressBar();
    }
    return worker;
    }
    void DelWorker(BackgroundWorker bgWk)
    {
    if (bgWk.IsBusy)
    bgWk.CancelAsync();
    lock (verrou)
    {
    lstBgWorker.Remove(bgWk.GetHashCode());
    if (lstBgWorker.Count == 0)
    StopProgressBar();
    }
    }
    //actions pour afficher les donn‚es !
    void worker_Completed(object sender, RunWorkerCompletedEventArgs e)
    {
    try
    {
    if (!e.Cancelled)
    {
    StopProgressBar();
    progressBar.Value = 100;
    AsynchroneMethode func = (AsynchroneMethode)e.Result;
    switch (func.Methode)
    {
    caseMethodeName.RechercheClient:
    MaFenetre.LoadUserControl(newRecherche(func.Arguments[0].ToString()));
    break;
    caseMethodeName.FicheClientByDossier:
    caseMethodeName.FicheClientByClient:
    MaFenetre.LoadUserControl(newFicheClient((DossierOuvert)func.Retour));
    MaFenetre.DossierEncoursGrid.SelectedItem = (DossierOuvert)func.Retour;
    break;
    caseMethodeName.FicheMission:
    MaFenetre.MaFicheClient.AfficheMission((List<Mission>)func.Retour);
    break;
    caseMethodeName.FicheEcriture:
    MaFenetre.MaFicheClient.AfficheComptesAsynch();
    break;
    caseMethodeName.SauveFicheClient:
    MonApplication.VueRelance.FermeDossierOuvert((int)func.Arguments[0]);
    break;
    caseMethodeName.SauveFicheClientSansFermer:
    caseMethodeName.ChangeFicheEcriture:
    break;
    }
    progressBar.Value = 0;
    }
    else
    {
    }
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    DelWorker((BackgroundWorker)sender);
    }
    //traitement
    privatevoid worker_Traitement(object myWorker, DoWorkEventArgs e)
    {
    AsynchroneMethode func = (AsynchroneMethode)e.Argument;
    try
    {
    switch (func.Methode)
    {
    caseMethodeName.RechercheClient:
    MonApplication.VueRelance.RechercheClientRequette = func.Arguments[0].ToString();
    func.Retour = MonApplication.VueRelance.RechercheClientResultats;
    break;
    caseMethodeName.FicheClientByDossier:
    DossierOuvert dossierOuvert = MonApplication.VueRelance.AddDossierOuvert((int)func.Arguments[0]);
    func.Retour = dossierOuvert;
    break;
    caseMethodeName.FicheClientByClient:
    string codeClient = func.Arguments[0].ToString();
    DossierOuvert dossierOuvertClient = null;
    Dossier dossier = AppRelance.VueRelance.GetDossierByClient(codeClient);
    if (dossier == null)
    {
    Client client = AppRelance.VueRelance.GetClient(codeClient);
    dossierOuvertClient = new Entreprise.Relance.Client.ModelView.DossierOuvert(client);
    }
    else
    dossierOuvertClient = new Entreprise.Relance.Client.ModelView.DossierOuvert(dossier);
    func.Retour = AppRelance.VueRelance.AddDossierOuvert(dossierOuvertClient);
    break;
    caseMethodeName.FicheMission:
    List<Mission> miss = MonApplication.VueRelance.PGIGetMission(func.Arguments[0].ToString());
    func.Retour = miss;
    break;
    caseMethodeName.FicheEcriture:
    MonApplication.VueRelance.InitEcritures(func.Arguments[0].ToString(), true, MonApplication.VueRelance.PGICodeExercice[0]);
    break;
    caseMethodeName.ChangeFicheEcriture:
    MonApplication.VueRelance.ChangeEcritures(func.Arguments[0].ToString(), (bool)func.Arguments[1], func.Arguments[2].ToString());
    break;
    caseMethodeName.SauveFicheClient:
    caseMethodeName.SauveFicheClientSansFermer:
    MonApplication.VueRelance.SaveDossierOuvert((int)func.Arguments[0]);
    break;
    }
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    e.Result = func;
    }
    #endregion
    publicvoid StartProcess(MethodeName genreDeMethode, paramsobject[] arguments)
    {
    AsynchroneMethode metho = newAsynchroneMethode(genreDeMethode, arguments);
    BackgroundWorker bgWorker = NewWorker();
    bgWorker.RunWorkerAsync(metho);
    }
     
    }
     
    publicclassAsynchroneMethode
    {
    publicMethodeName Methode;
    publicList<object> Arguments = newList<object>();
    publicobject Retour = null;
    public AsynchroneMethode(MethodeName methode, paramsobject[] list)
    {
    Methode = methode;
    for (int i = 0; i < list.Length; i++)
    {
    Arguments.Add(list[i]);
    }
    }
    }
    publicenumMethodeName
    {
    RechercheClient = 1,
    FicheClientByDossier = 2,
    FicheClientByClient = 3,
    FicheMission = 4,
    FicheEcriture = 5,
    ChangeFicheEcriture = 6,
    SauveFicheClient = 7,
    SauveFicheClientSansFermer = 8
    }
    }
    *********************

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <UserControl x:Class="RelanceWPF.UCProgressBar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="24" Width="420">
    <UserControl.Resources>
    <Storyboard x:Name="StoryProgressBar" x:Key="StoryProgressBar" >
    <DoubleAnimation
    RepeatBehavior="Forever"
    Storyboard.TargetName="progressBar"Storyboard.TargetProperty="Value"
    From="0" To="100" Duration="0:0:5"/>
    </Storyboard>
    </UserControl.Resources>
    <Grid x:Name="MaGrid">
    <ProgressBar VerticalAlignment="Stretch" Grid.Row="4" Grid.ColumnSpan="4" x:Name="progressBar" >
    <ProgressBar.Background>
    <LinearGradientBrush EndPoint="0.444,0.129" StartPoint="0.444,-0.118">
    <GradientStop Color="#FF134E60" Offset="0"/>
    <GradientStop Color="#FFECF6F9" Offset="0.986"/>
    </LinearGradientBrush>
    </ProgressBar.Background>
    </ProgressBar>
    </Grid>
    </UserControl>
    
    

  9. #9
    Membre expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Points : 3 015
    Points
    3 015
    Par défaut
    Cool

    N'oublie le Tag
    Et puis tu peux utiliser les balises codes (même si tu as réussi à garder les couleurs ce qui rend le code plus ou moins visible )

  10. #10
    Membre à l'essai
    Inscrit en
    Janvier 2008
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 27
    Points : 24
    Points
    24
    Par défaut
    Voila c'est fait pour la balise CODE , par contre les tabulations sont perdu.

    Merci de vos réponses si rapide.

    A+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment importer une animation de Blender dans du code C++?
    Par zuzuu dans le forum Développement 2D, 3D et Jeux
    Réponses: 4
    Dernier message: 01/12/2008, 11h16
  2. Réponses: 1
    Dernier message: 17/02/2006, 19h18
  3. Réponses: 1
    Dernier message: 10/02/2006, 16h59
  4. Réponses: 3
    Dernier message: 25/11/2002, 14h15
  5. comment integer une animation swf dans une page
    Par naili dans le forum Intégration
    Réponses: 7
    Dernier message: 18/09/2002, 18h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo