首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >动画XAML Eclipse用于Pushpin控件

动画XAML Eclipse用于Pushpin控件
EN

Stack Overflow用户
提问于 2013-07-09 04:15:56
回答 1查看 673关注 0票数 0

我有点像XAML,所以这可能是我错过的很简单的事情.

在一个Windows 8应用程序中,我有一个地图Pushpin,我试图用一种非常类似于池塘中的涟漪的效果来动画。我有一个大型容器eclipse和一个子eclipse,它将从0宽度/高度扩展到30宽度/高度(与父eclipse大小相同)。

我这样做是为了直观地向用户表明他们的位置正在被主动跟踪,或者只是被捕获。

不幸的是,我没有设法让我的动画工作。

代码语言:javascript
复制
<ControlTemplate x:Key="UserLocationPushpinControlTemplate" TargetType="m:Pushpin">
    <Grid x:Name="ContentGrid" Width="34" Height="34">
        <Grid.Resources>
            <Storyboard x:Name="Storyboard1">
                <DoubleAnimation
                    Storyboard.TargetName="Animated"
                    Storyboard.TargetProperty="Width"
                    From="0" To="30" Duration="0:0:1" AutoReverse="False" 
                    RepeatBehavior="Forever" />
                <DoubleAnimation
                    Storyboard.TargetName="Animated"
                    Storyboard.TargetProperty="Height"
                    From="0" To="30" Duration="0:0:1" AutoReverse="False" 
                    RepeatBehavior="Forever" />
            </Storyboard>
        </Grid.Resources>
        <Grid MinHeight="30" MinWidth="30">
            <Ellipse x:Name="Parent" Margin="1"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="30"
                Height="30"
                Stroke="White"
                StrokeThickness="3"
                Fill="{StaticResource PrimaryColorBrush}"/>
            <Ellipse x:Name="Animated" Margin="1"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="0"
                Height="0"
                Stroke="White"
                StrokeThickness="2"/>
        </Grid>
    </Grid>
</ControlTemplate>

以防万一--这个ControlTemplate在一个UserControl内,里面有我的Windows 7/ Bing地图控件( Windows 8地图控件缺少一些我需要的功能)。

任何帮助都将不胜感激。谢谢。

更新

我可以添加一个动画,但不知道如何通过代码应用故事板。理想情况下,我想通过代码应用Storyboard,因为我想为不同的情况定义几个。

以下是更新的XAML:

代码语言:javascript
复制
    <ControlTemplate x:Key="UserLocationPushpinControlTemplate" TargetType="m:Pushpin">
        <Grid x:Name="ContentGrid" Width="34" Height="34">
            <Grid.Resources>
                <Storyboard x:Name="LocateStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="AnimatedEllipse" RepeatBehavior="Forever">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="30"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="AnimatedEllipse" RepeatBehavior="Forever">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="30"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </Grid.Resources>
            <Grid MinHeight="30" MinWidth="30">
                <Ellipse x:Name="ParentEllipse" Margin="1"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Width="30"
                    Height="30"
                    Stroke="White"
                    StrokeThickness="3"
                    Fill="{StaticResource PrimaryColorBrush}"/>
                <Ellipse x:Name="AnimatedEllipse" Margin="1"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Width="0"
                    Height="0"
                    Stroke="White"
                    StrokeThickness="2"/>
            </Grid>
        </Grid>
    </ControlTemplate>

顺便提一句:在创建动画之前,我遇到了一些问题,因为我不知道如果您直接调整XAML代码,Blend不会记录更改。您需要查找各种属性控件,并在那里设置所有内容。

这是我用来启动动画的代码:

代码语言:javascript
复制
Pushpin pushpin = new Pushpin();
pushpin.Tag = PIN_TAG;
pushpin.Location = ViewModel.Location;
pushpin.Template = (ControlTemplate)Resources["UserLocationPushpinControlTemplate"];
pushpin.PositionOrigin = PositionOrigin.Center;
MapBase.Children.Add(pushpin);

Storyboard animation = (Storyboard)pushpin.Resources["LocateStoryboard"];
animation.Begin();

情节提要变量为空。看来,我需要深入研究ControlTemplate结构,才能深入到"LocateStoryboard“资源。有什么办法吗?

EN

回答 1

Stack Overflow用户

发布于 2013-07-10 07:24:07

不确定它是否有用,但是看看伊戈尔·拉利奇的文章..。,他有一个关于如何在图钉上添加淡出动画的详细示例。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17539807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档