在wpf中的图片(只在圆圈中点击不在正方形,圆圈在正方形内)

时间:2011-05-21 05:47:33

标签: wpf

我的程序中有一张照片

在这张照片中,正方形中有一个正方形和一个圆圈

在我的程序中,当用户点击圆圈时,我的动画将会执行。(只在圆圈中单击不在正方形中,圆圈在正方形内)。请帮我写这段代码

提前致谢

1 个答案:

答案 0 :(得分:0)

使用Blend SDK,您可以使用ControlStoryboardAction

在Xaml中完整地编写此内容
<Window ...
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:im="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"
    >
   <Window.Resources>
    <Storyboard x:Name="Storyboard1">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="ellipse">
            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.75"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="ellipse">
        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.75"/>
    </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    </Window.Resources>
    <Canvas Margin="56,104,114,248">
        <Rectangle Fill="#FFF4F4F5" Height="157" Canvas.Left="60" Stroke="Black" Canvas.Top="51" Width="170"/>
    <Ellipse x:Name="ellipse" Fill="#FFE48A06" Height="115" Canvas.Left="89" Stroke="Black" Canvas.Top="76" Width="119" RenderTransformOrigin="0.5,0.5">
        <Ellipse.RenderTransform>
        <CompositeTransform/>
    </Ellipse.RenderTransform>
    <Custom:Interaction.Triggers>
        <Custom:EventTrigger EventName="MouseLeftButtonDown">
        <im:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
        </Custom:EventTrigger>
    </Custom:Interaction.Triggers>
    </Ellipse>
</Canvas>
</Window>

BTW:我为Windows Phone做了这个,所以可能需要对WPF进行一点调整。