Featured Post

Organize and rename photos by EXIF data with PowerShell

This PowerShell script organizes and renames all photos in a selected folder using EXIF data. It will also create thumbnails of the images i...

Friday, October 18, 2013

Simple Elegant Busy Indicator for WPF

<Control Grid.Column="0" Grid.Row="3"
            Grid.ColumnSpan="1" Grid.RowSpan="1"
            Width="100" Height="100" VerticalAlignment="Top"  HorizontalAlignment="Left">
    <Control.Style>
        <Style TargetType="Control">
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Control">
                        <Viewbox>
                            <Canvas RenderTransformOrigin="0.5,0.5" Width="100" Height="100">
                                <Canvas.Resources>
                                    <Style TargetType="{x:Type Ellipse}">
                                        <Setter Property="Stretch" Value="Fill"/>
                                        <Setter Property="Fill" Value="Black"/>
                                    </Style>
                                </Canvas.Resources>
                                <Ellipse Width="21.835" Height="21.862" Canvas.Left="20.1696" Canvas.Top="9.76358" Opacity="1.0"/>
                                <Ellipse Width="20.835" Height="20.862" Canvas.Left="2.86816" Canvas.Top="29.9581" Opacity="0.9"/>
                                <Ellipse Width="19.835" Height="19.862" Canvas.Left="0.00001" Canvas.Top="57.9341" Opacity="0.8"/>
                                <Ellipse Width="17.835" Height="17.862" Canvas.Left="12.1203" Canvas.Top="83.3163" Opacity="0.7"/>
                                <Ellipse Width="16.835" Height="16.862" Canvas.Left="36.5459" Canvas.Top="98.1380" Opacity="0.6"/>
                                <Ellipse Width="14.835" Height="14.862" Canvas.Left="64.6723" Canvas.Top="96.8411" Opacity="0.5"/>
                                <Ellipse Width="13.835" Height="13.862" Canvas.Left="87.6176" Canvas.Top="81.2783" Opacity="0.4"/>
                                <Ellipse Width="12.835" Height="12.862" Canvas.Left="98.165"  Canvas.Top="54.4140" Opacity="0.3"/>
                                <Ellipse Width="11.835" Height="11.862" Canvas.Left="92.9838" Canvas.Top="26.9938" Opacity="0.2"/>
                                <Canvas.RenderTransform>
                                    <RotateTransform x:Name="SpinnerRotate" Angle="0"/>
                                </Canvas.RenderTransform>
                                <Canvas.Triggers>
                                    <EventTrigger RoutedEvent="ContentControl.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="SpinnerRotate" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:01.3" RepeatBehavior="Forever"/>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Canvas.Triggers>
                            </Canvas>
                        </Viewbox>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Control.Style>
</Control>

You can easily bind the Visibility to a property to control when it is shown/hidden:
Visibility="{Binding ShowThinking, Converter={StaticResource BooleanToVisibilityConverter}}"
Derived from: http://stackoverflow.com/a/8668682/1992193

No comments:

Post a Comment