WPF C#轮盘游戏

时间:2013-12-14 13:18:36

标签: c# wpf

我想在WPF中创建轮盘赌游戏#下面提到的代码工作正常,但我想在3秒后停止转动,但我没有办法做到这一点。请帮助我同样的

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfApplication2.MainWindow" Title="MainWindow" WindowState="Maximized">
<Canvas>
    <Canvas.Background>
        <ImageBrush ImageSource="Image/Background.jpg" AlignmentX="Right" AlignmentY="Bottom" Stretch="None"/>
    </Canvas.Background>
    <Ellipse Height="250" Width="250" Margin="200,100,-200,-100">
        <Ellipse.Fill>
            <ImageBrush x:Name="p2" ImageSource="Image/p2.png"/>
        </Ellipse.Fill>
        <Ellipse.RenderTransform>
            <RotateTransform x:Name="TransRotate11" CenterX="125" CenterY="125"/>
        </Ellipse.RenderTransform>
        <Ellipse.Triggers>
            <EventTrigger RoutedEvent="Image.Loaded">
                <BeginStoryboard>
                    <Storyboard x:Uid="s1" TargetProperty="Angle" RepeatBehavior="Forever">
                        <DoubleAnimation By="360" Duration="0:0:0.1" Storyboard.TargetName="TransRotate11" Storyboard.TargetProperty="Angle" FillBehavior="Stop"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Ellipse.Triggers>
    </Ellipse>
</Canvas>

1 个答案:

答案 0 :(得分:0)

如果动画的持续时间是0.1秒并且您希望它运行3秒,为什么不简单地将其RepeatBehavior设置为30次:

<Storyboard x:Uid="s1">
    <DoubleAnimation Storyboard.TargetName="TransRotate11"
                     Storyboard.TargetProperty="Angle"
                     By="360" Duration="0:0:0.1"
                     RepeatBehavior="30x" FillBehavior="Stop" />
</Storyboard>