On the Loaded handler of the Window, I've this:
Loaded += scaleUp;
anim = new DoubleAnimation() {
Duration = TimeSpan.FromSeconds(0.5),
EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn }
};
void scaleUp(object sender, RoutedEventArgs e) {
RenderTransform = new ScaleTransform(1, 1, ActualWidth/2, ActualHeight/2);
anim.From = 0;
RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, anim);
}
so it scales up when it opens:

and when I click on cancelButton:
var cancelButton = new ActionButton() {
Icon = Icons.CloseCircle,
HorizontalAlignment = HorizontalAlignment.Right,
Command = () => {
DialogResult = false;
scaleDown();
}
};
it sets the DialogResult and calls scaleDown:
void scaleDown() {
anim.Completed += onAnimationCompleted;
anim.To = 0;
//anim.From = ActualHeight;
//BeginAnimation(HeightProperty, anim);
RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, anim);
}
void onAnimationCompleted(object sender, EventArgs e) {
anim.Completed -= onAnimationCompleted;
Close();
}
BUT it doesn't animate!
EDIT
The DialogResult actually closes the window so with this in cancelButton:
var cancelButton = new ActionButton() {
Icon = Icons.CloseCircle,
HorizontalAlignment = HorizontalAlignment.Right,
Command = () => scaleDown(false)
};
and this in scaleDown:
void scaleDown(bool value) {
anim.Completed += (s,e) => DialogResult = value;
anim.To = 0;
anim.From = ActualHeight;
BeginAnimation(HeightProperty, anim);
//RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, anim);
}
it does animate the Height. ScaleTransform.ScaleYProperty doesn't work
