I\'m trying to figure out how to animate the change from Visibile to Hidden for a WPF window. The way I currently have the application working is that the window is normally
I did something like that (opacity goes to 0 during 2 seconds and window hides): just look at code, it's simple
MainWindow.xaml:
MainWindow.xaml.cs
public void ShowMe() {
(FindResource("showMe") as Storyboard).Begin(this);
}
public void HideMe() {
(FindResource("hideMe") as Storyboard).Begin(this);
}
Just call HideMe()
or ShowMe()
instead of setting Visibility = Visibility.Hidden
in code
Edit
WPF is slow when moving windows, so if you need sliding animation:
Make a transparent window (AllowsTransparency="True" Background="Transparent" WindowStyle="None"
)
Put all your controls onto opaque panel (Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}"
)
Animate this panel's Margin.Left
from 0
to window's ActualWidth
, then hide a window - this will remove a problem of saving window size