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
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
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.
System.Windows.Forms
View Application Events
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.
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:
Preview:
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:
WindowsFormsIntegration
and System.Windows.Forms
assemblies.Add following namespace to Window
element
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Add ProgressBar
to WindowsFormsHost
control. For example
<WindowsFormsHost Margin="0,10,0,0">
<wf:ProgressBar x:Name="DownloadProgressBar" Width="500" Height="50" />
</WindowsFormsHost>
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();