【问题标题】:WPF C# Roulette GameWPF C# 轮盘游戏
【发布时间】:2013-12-14 13:18:36
【问题描述】:

我想在 WPF C# 中创建轮盘游戏,下面提到的代码工作正常,但我想在 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>

【问题讨论】:

  • 请发布格式化的 XAML 代码。

标签: c# wpf


【解决方案1】:

如果动画的持续时间是 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>

【讨论】:

    猜你喜欢
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    相关资源
    最近更新 更多