Animando uma largura e altura da janela do WPF
Eu gostaria de animar a largura e a altura de uma janela wpf. Eu tentei o seguinte, que infelizmente apenas anima a largura ... a altura da janela nunca muda.
Tenho certeza que eu perdi algo bobo e espero que, postando aqui alguém vai ver o meu erro!
Aqui está o código por trás de uma janela simples com um botão que eu usei para fazer o redimensionamento:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.AnimateWindowSize(ActualWidth + 200, ActualHeight + 200);
}
}
E aqui está o código de animação que eu escrevi como um método de extensão para que ele possa ser aplicado a qualquer janela ...
public static class WindowUtilties
{
public static void AnimateWindowSize(this Window target, double newWidth, double newHeight)
{
var sb = new Storyboard {Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200))};
var aniWidth = new DoubleAnimationUsingKeyFrames();
var aniHeight = new DoubleAnimationUsingKeyFrames();
aniWidth.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));
aniHeight.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));
aniHeight.KeyFrames.Add(new EasingDoubleKeyFrame(target.ActualHeight, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 00))));
aniHeight.KeyFrames.Add(new EasingDoubleKeyFrame(newHeight, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 200))));
aniWidth.KeyFrames.Add(new EasingDoubleKeyFrame(target.ActualWidth, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 00))));
aniWidth.KeyFrames.Add(new EasingDoubleKeyFrame(newWidth, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 200))));
Storyboard.SetTarget(aniWidth, target);
Storyboard.SetTargetProperty(aniWidth, new PropertyPath(Window.WidthProperty));
Storyboard.SetTarget(aniHeight, target);
Storyboard.SetTargetProperty(aniHeight, new PropertyPath(Window.HeightProperty));
sb.Children.Add(aniWidth);
sb.Children.Add(aniHeight);
sb.Begin();
}
}
Agradecemos antecipadamente por qualquer ajuda.