'How can I animate a WPF Grid to slide in from the left and out to the left when Visibility changes?
I have a WPF Grid as follows:
<Grid x:Name="Main Panel">
<Grid x:Name="Detail Panel 1"></Grid>
<Grid x:Name="Detail Panel 2" Visibility="Collapsed"></Grid>
</Grid>
And a style that expands it when visibility changes. But really I want it to slide in/out rather than expand and compress
<!-- Defined animation for appearance of Panel to slide in/out from left side-->
<Style TargetType="Grid" x:Key="expand">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX"
From="0"
Duration="0:00:01"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
EDIT
I replaced the scale transform with a translate transform as follows, which sort of works except it seems the right side of the incoming grid is always pinned to the right side.
So how would I make the grid slide in with a fixed width equal to the parents width such that it appears like a page sliding in over the lower grid layers?
<!-- Defined animation for appearance of Panel to slide in/out from left side-->
<Style TargetType="Grid" x:Key="slidein">
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform X="0"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.X"
From="-1000"
Duration="0:00:01"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
