Animation on other targets
Last Post 09 Jul 2015 08:49 AM by Filip Dušek. 1 Replies.
Printer Friendly
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
J. Alan AthertonUser is Offline
New Member
New Member

09 Jul 2015 12:41 AM
    I am trying to make an animation happen for a StackPanel when a button is pressed. The effect I want is a sliding menu that appears when a button is pressed. I know the animation itself works because I currently have it connected to the visibility property.

    Here's what I am trying now:
        <Canvas Background="Transparent" x:Name="backgroundCanvas">
            <StackPanel x:Name="PathPanel" Orientation="Vertical" Canvas.Left="50" Canvas.Top="0" MinWidth="500" Width="Auto" Background="#E0E8F0">

    The StackPanel of interest has name PathPanel.

    Farther down, a child of PathPanel:
                <ToggleButton Content="Paths"  Focusable="False" x:Name="PathToggle">
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                                    <DoubleAnimation Storyboard.TargetName="PathPanel" Storyboard.TargetProperty="(Canvas.Top)" From="-200" To="0" Duration="0:0:0.25" >
                                            <PowerEase EasingMode="EaseOut" />

    When I uncheck the toggle button, I get an ArgumentNullException in the UI UpdateInput method call. It appears to be the Storyboard.TargetName that causes the problem. Is there a way to do this?
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member

    09 Jul 2015 08:49 AM
    Yes, this would work only in Control Template in current version. The problem is that when I was implementing animations I still didn't have good way to find a control by name outside of Templates. I do have that now, so let me add this feature to my priority list.

    BUT I knew that this can be an issue so there is a workaround. It's little hack, which I left there in case I need something like this. You can make a method in partial class for your UI Root like this:

            public void SetAnimTarget()
                EventTrigger trigger = PathToggle.Triggers[0] as EventTrigger;
                BeginStoryboard begin = trigger.Actions[0] as BeginStoryboard;
                Storyboard.SetTarget(begin.Storyboard.Children[0], PathPanel);

    Don't forget to call this method somewhere. The way it works is very simple. If you set Target for animation, it will be used without searching for target by name.
    You are not authorized to post a reply.