使用按钮更改视觉状态

Change visual state with button

我目前正在 UWP 平台上开发一个应用程序,尽管它不是很重要,因为它只是学校工作,但我希望在菜单打开时进行一些平滑的过渡。我制作了两种状态的菜单,但我不知道如何在按下“打开菜单”按钮时更改状态,有人知道该怎么做吗?

顺便说一句,菜单是一个StackPanel,希望我选对它

感谢您的宝贵时间

我相信这应该可以解决问题:

将这些添加到拥有 window/page/control:

xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"

并将按钮设置为:

 <Button x:Name="TheButton"
                Content="Transition">

            <i:Interaction.Behaviors>

                <core:EventTriggerBehavior EventName="Click">

                    <core:GoToStateAction StateName="TheStateToMoveTo"
                                          TargetObject="{Binding ElementName=NameOfTheObjectWithTheStates}"
                                          UseTransitions="True" />

                </core:EventTriggerBehavior>

            </i:Interaction.Behaviors>

        </Button>

事件应该被触发器捕获并且行为应该使状态转换发生。