WPF loading spinner

后端 未结 14 832
我寻月下人不归
我寻月下人不归 2020-12-02 05:30

The goal is to display the information that the application is working. So I\'m looking for an intelligent implementation sample of a loading spinner using WPF / MVVM.

相关标签:
14条回答
  • 2020-12-02 06:22

    In WPF, you can now simply do:

    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; // set the cursor to loading spinner
    
    Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; // set the cursor back to arrow
    
    0 讨论(0)
  • 2020-12-02 06:22

    You can do it without any additional controls and libraries, using only Image control and transform:

    <Image
        Source="/images/spinner.png"
        Width="100"
        Height="100"
        RenderTransformOrigin="0.5, 0.5" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}">
        <Image.RenderTransform>
            <RotateTransform x:Name="noFreeze" />
        </Image.RenderTransform>
        <Image.Triggers>
            <EventTrigger RoutedEvent="Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)"
                            To="360" Duration="0:0:1" RepeatBehavior="Forever" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Image.Triggers>
    </Image>
    

    Replace /images/spinner.png with your image. Change To="360" to To="-360" if you want to rotate it counterclockwise. Duration="0:0:1" equals to 1 second per rotation.

    0 讨论(0)
提交回复
热议问题