4

The progress bars in Windows Forms applications have the standard "shine" animation, but when I try to add a progress bar in WPF I don't get such a thing by default. How do we get this back with WPF in Windows 8?

Windows Forms

WPF

Community
  • 1
  • 1
tina nyaa
  • 991
  • 4
  • 13
  • 25

3 Answers3

2

It's a rather bizzare fix, but you need to enable Windows Forms styles in your application to use the "gloss." Here's how I did it.

  1. Add a reference in your project to System.Windows.Forms
  2. Go to the Project settings page and click View Application Events
  3. Add a handler to your Application.Startup using the following code (in VB.NET, C# similar) (also, if you need to include the arguments, do so)
Class Application

    ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
    ' can be handled in this file.

    Private Sub Application_Startup() Handles Me.Startup
        System.Windows.Forms.Application.EnableVisualStyles()
    End Sub

End Class

It seems weird that you would have to call this in order to get the WPF progressbar to work, but the code works for me.

Milliron X
  • 1,174
  • 14
  • 26
0

If you want ultimate control over the look (namely the color of the indicator), I have tweaked a control I found on another SO post, which gives near-identical display.

Tweak:

<Grid Background="LightGray">
    <Grid Width="{Binding ProgressBarWidth, ElementName=uc}" HorizontalAlignment="Left">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Rectangle.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Background.(GradientBrush.GradientStops)[1].(GradientStop.Offset)" From="-1" To="0" Duration="0:0:1.5" RepeatBehavior="Forever"/>
                        <DoubleAnimation Storyboard.TargetProperty="Background.(GradientBrush.GradientStops)[2].(GradientStop.Offset)" From="0" To="1" Duration="0:0:1.5" RepeatBehavior="Forever"/>
                        <DoubleAnimation Storyboard.TargetProperty="Background.(GradientBrush.GradientStops)[3].(GradientStop.Offset)" From="1" To="2" Duration="0:0:1.5" RepeatBehavior="Forever"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
        <Grid.Background>
            <LinearGradientBrush>
                <GradientStop Color="#FF218ED6" Offset="0.0" />
                <GradientStop Color="#FF4BA5E0" Offset="0.4" />
                <GradientStop Color="#FF8ECCF5" Offset="0.5" />
                <GradientStop Color="#FF4BA5E0" Offset="0.6" />
                <GradientStop Color="#FF218ED6" Offset="1.0" />
            </LinearGradientBrush>
        </Grid.Background>
    </Grid>
</Grid>

Full Implementation:

Progress bar style in WPF is old fashioned. Increments in Bars. How to implement a progress bar with vista or windows-7 shady glow effect?

Preview:

enter image description here

Community
  • 1
  • 1
0

Milliron X answer didn't help me so I had to use Windows Forms ProgressBar instead of reinventing the wheel using custom control.

To achieve this:

  1. Add reference to WindowsFormsIntegration and System.Windows.Forms assemblies.
  2. Add following namespace to Window element

    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    
  3. Add ProgressBar to WindowsFormsHost control. For example

    <WindowsFormsHost Margin="0,10,0,0">
        <wf:ProgressBar x:Name="DownloadProgressBar" Width="500" Height="50" />
    </WindowsFormsHost>
    
  4. For our ProgressBar not to look "old-style" you need to add following line to your entry point (e.g. Main method or Application.OnStartUp method):

    System.Windows.Forms.Application.EnableVisualStyles();
    
Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90