Hello,
Welcome to Microsoft Q&A!
You could try to use DataTriggerBehavior and GoToStateAction from XAML Behaviors SDK to get your target.
Here is a simple sample that I made
<Page.Resources>
<Storyboard x:Name="myAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="targetstackpanel" Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:05" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="targetstackpanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="-25"/>
<EasingDoubleKeyFrame KeyTime="00:00:05" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Page.Resources>
<Grid x:Name="RootGrid">
<Button Content="Click" Click="Button_Click"/>
<StackPanel x:Name="targetstackpanel" Background="Aqua" Width="200" Visibility="Collapsed" Height="200" Margin="24,0,0,0">
<StackPanel.RenderTransform>
<CompositeTransform />
</StackPanel.RenderTransform>
<TextBlock Text="This is a Text" Foreground="BlueViolet"/>
</StackPanel>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding Visibility, ElementName=targetstackpanel}" Value="Visible">
<Core:CallMethodAction TargetObject="{Binding}" MethodName="StartAnimation"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Grid>
Code-behind:
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
targetstackpanel.Visibility = Visibility.Visible;
}
public void StartAnimation()
{
myAnimation.Begin();
}
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.