Windows Phone 8 - 展开/折叠地图控件

时间:2013-02-27 18:56:31

标签: windows-phone-8 windows-phone bing-maps

这是我的页面,显示了用户的当前位置:

enter image description here

在地图控件的左下角,有一个展开按钮。单击时,地图控件应扩展为全屏,按钮应更改为折叠按钮。这很容易,但我想为扩展和折叠过程设置动画。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

有关XAML元素的动画属性的概述,请查看此处...

http://windowsphonegeek.com/articles/wp7-animations-in-depthndash-overview-and-getting-started

对于Map,这里有一些C#代码可以为其“Height”属性设置动画...

        // assumes Map element is called 'map'
        double height = map.Height;
        double from, to;

        // animate from 150 to 800, or vice versa
        if (height == 150)
        {
            from = 150;
            to = 800;
        }
        else
        {
            from = 800;
            to = 150;
        }

        Storyboard sb = new Storyboard();
        DoubleAnimation fillHeightAnimation = new DoubleAnimation();
        fillHeightAnimation.From = from;
        fillHeightAnimation.To = to;
        fillHeightAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));

        Storyboard.SetTarget(fillHeightAnimation, map);
        Storyboard.SetTargetProperty(fillHeightAnimation, new PropertyPath("Height"));

        sb.Children.Add(fillHeightAnimation);
        sb.Begin();