开发者

WPF : How to animate a button on click of another button?

I have the following XAML code:

<Button Content="Menu 1" Height="23" Name="button1" Width="75" Margin="10">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="Button.MouseEnter">
                    <EventTrigger.Actions>
                        <BeginStoryb开发者_运维问答oard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TranslateTransform.Y)" From="0" To="200" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
    <Button.RenderTransform>
        <TranslateTransform X="0" Y="0" />
    </Button.RenderTransform>
</Button>

This code moves the button in the Y direction when the mouse is over the button. However, I want the same functionality when I move my mouse over another button. In short, let's assume I have Button1 and Button2. When I move my mouse over Button1, the Button2 should move down in the Y direction. How can I achieve this. Could anyone provide a working XAML code for the same.


You could subclass Button and add a property named ButtonToAnimate.

In the event trigger, point the Target of the DoubleAnimation to the ButtonToAnimate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜