0

我是 WPF 新手,使用加载动画我想在动画的点更改上加载事件我尝试了很多,但事件在窗口出现之前加载。

<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
    <StackPanel.Triggers>
        <EventTrigger RoutedEvent="Rectangle.Loaded">
            <BeginStoryboard>
                <Storyboard Name="waitingAnimation" RepeatBehavior="1x" >
                    <DoubleAnimation Storyboard.TargetName="Dot1" BeginTime="0:0:0.0" Storyboard.TargetProperty="Opacity" From=".1" To="1" AutoReverse="False" Duration="0:0:5.0"/>
                    <DoubleAnimation Storyboard.TargetName="Dot2" BeginTime="0:0:5.0" Storyboard.TargetProperty="Opacity" From=".1" To="1" AutoReverse="False" Duration="0:0:5.0"  />
                    <DoubleAnimation Storyboard.TargetName="Dot3" BeginTime="0:0:10.0" Storyboard.TargetProperty="Opacity" From=".1" To="1" AutoReverse="False" Duration="0:0:5.0"  />
                    <DoubleAnimation Storyboard.TargetName="Dot4" BeginTime="0:0:15.0" Storyboard.TargetProperty="Opacity" From=".1" To="1" AutoReverse="False" Duration="0:0:5.0"/>
                    <DoubleAnimation Storyboard.TargetName="Dot5" BeginTime="0:0:20.0" Storyboard.TargetProperty="Opacity" From=".1" To="1" AutoReverse="False" Duration="0:0:5.0"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </StackPanel.Triggers>
    <Ellipse Name="Dot1" Fill="White" Opacity=".1" Width="8" Height="8" />
    <Ellipse Name="Dot2" Fill="White" Opacity=".1" Width="8" Height="8" Margin="2,0,0,0" />
    <Ellipse Name="Dot3" Fill="White" Opacity=".1" Width="8" Height="8" Margin="2,0,0,0"/>
    <Ellipse Name="Dot4" Fill="White" Opacity=".1" Width="8" Height="8" Margin="2,0,0,0" Loaded="Dot4_Loaded"/>
    <Ellipse Name="Dot5" Fill="White" Opacity=".1" Width="8" Height="8" Margin="2,0,0,0"/>
</StackPanel>

后面的代码:

public StartUp()
{
    InitializeComponent();
    this.WindowState = WindowState.Maximized;
}

private void Dot4_Loaded(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Hi");
}
4

0 回答 0