Does anybody know how to change the foreground color of a WPF-Progressbar. It always seems to be merged with green.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Use style and customize as per yours requirement
just try with this
If it is not working as you required you have to modify the Style or ControlTemplate of Progressbar.
To do that you can use Expression Blend from Microsoft or you can get a copy the existing template and modify it.
Unfortunately, it is hard coded in default style:
You can create your own style from original XAML or try to override background in the Loaded event for example:
but it's unreliable
Why not take a path of low resistance and use the popular MahApps library?
Setup the namespace:
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
Add the 'MetroProgressBar'
Set the 'Foreground' to your favorite color
I came across a similar issue when the Windows visual settings were optimised for best performance (Control Panel -> System -> Advanced System Settings -> Advanced -> Performance -> Settings -> Visual Effects -> Adjust for best performance). The progress bar looked fine under normal settings, but horrible under "best performance". I just changed ForeGround to "LightGreen".
Here's what I saw on default ForeColor under normal conditions
Here's what I saw when adjusted for best performance
Here is the change
Here's what I saw after when adjusted for best performance
Some more detail: http://justmycode.blogspot.com.au/2012/08/the-case-of-strangely-coloured.html
Marat Khasanov pointed out that the unwanted green tint comes from the object named "Animation" within the control template. So another easy approach is to hide that object. This will also disable the animated "glow" effect, which I considered to be an asset but you might see as a deal-killer. I implemented this through a handler for the Loaded event as shown below.
This was inspired by an answer to another question. The same caveat applies: if they change the control template then this might no longer work.