Windows 8 WPF performance templates do not have a glow

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

Windows forms

WPF

+4
source share
3 answers

This is more of a bizzare fix, but you need to enable Windows Forms styles in your application to use gloss. Here is how I did it.

  • Add a link to your project in System.Windows.Forms
  • Go to the project settings page and click View Application Events
  • Add a handler to your Application.Startup using the following code (in VB.NET, C # similar) (also, if you need to include arguments, do it)
 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 strange that you will need to call this in order to get a WPF progress bar, but the code works for me.

+2
source

If you need full control over the appearance (namely the color of the indicator), I changed the control that I found on another SO column, which gives an almost 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:

WPF's execution style is old fashioned. Increments in bars. How to implement a progress bar with shady vista or windows-7 effect?

Preview:

enter image description here

+1
source

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

To achieve this:

  • Add a link to the WindowsFormsIntegration and System.Windows.Forms assemblies.
  • Add the following namespace to the Window element

     xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
  • Add a ProgressBar to the WindowsFormsHost control. for instance

     <WindowsFormsHost Margin="0,10,0,0"> <wf:ProgressBar x:Name="DownloadProgressBar" Width="500" Height="50" /> </WindowsFormsHost> 
  • So that our ProgressBar does not look "old", you need to add the following line to your entry point (for example, the Main method or Application.OnStartUp ):

     System.Windows.Forms.Application.EnableVisualStyles(); 
0
source

Source: https://habr.com/ru/post/1491602/


All Articles