Animer la fenêtre Redimensionner (largeur et hauteur) C # WPF

Je cherche de l’aide pour animer le redimensionnement d’une fenêtre ouverte! Je n’arrive pas à comprendre celui-ci!

J’utilise juste atm.

this.Width = 500; 

Toute aide est la bienvenue! Merci.

J’ai répondu à cette question moi-même. Voici un exemple de code.

  static System.Windows.Forms.Timer _Timer = new System.Windows.Forms.Timer(); int _Stop = 0; private void This_Loaded(object sender, RoutedEventArgs e) { _Timer.Tick += new EventHandler(timer_Tick); _Timer.Interval = (20); resize(500,500) } private void timer_Tick(Object myObject, EventArgs myEventArgs) { if (_Stop == 0) { _RatioHeight = ((this.Height - _Height) / 12)* -1; _RatioWidth = ((this.Width - _Width) / 12)* -1; } _Stop++; this.Height += _RatioHeight; this.Width += _RatioWidth; if (_Stop == 12) { _Timer.Stop(); _Timer.Enabled = false; _Timer.Dispose(); _Stop = 0; this.Height = _Height; this.Width = _Width; } } public void resize(double _PassedHeight, double _PassedWidth) { _Height = _PassedHeight; _Width = _PassedWidth; _Timer.Enabled = true; _Timer.Start(); } 

Redimensionne la fenêtre en 12 “ticks” très rapidement, peut être ralentie dans _Timer.Interval. Après 12 ticks, il sera fini avec un redimensionnement final à la taille exacte.

J’espère que cela aide quelqu’un.

vous pouvez utiliser l’animation de la fenêtre pour cela, voici xaml

               

à l’animation utiliser un code comme ça

 Imports System.Windows.Media.Animation Public Class dlgControls Dim showWin As Storyboard Dim hideWin As Storyboard Private Sub btnOpen_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnOpen.Click BeginStoryboard(showWin) End Sub Private Sub dlgControls_Loaded(sender As Object, e As Windows.RoutedEventArgs) Handles Me.Loaded showWin = Me.Resources("showWin") hideWin = Me.Resources("hideWin") End Sub Private Sub btnClose_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnClose.Click BeginStoryboard(hideWin) End Sub End Class 
 System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += dispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0,0,0,0,10); // Control animation speed / how often the tick will be called. dispatcherTimer.Start(); private void dispatcherTimer_Tick(object sender, EventArgs e) { if ( this.Width < 500 ) { this.Width += 10; } else { DispatcherTimer timer = (DispatcherTimer)sender; timer.Stop(); } }