5

I have WPF application with ListView and ProgressBar inside. I define this color as Foreground to my ProgressBar:

enter image description here

under Windows 8 i can see this color but under Windows 7 i can see different color:

enter image description here

So my question is is it possible to see my desire color in all OS ?

Edit:

This is the style i created:

<Style x:Key="CustomProgressBar" TargetType="ProgressBar" >
    <Setter Property="Foreground" Value="#FF15669E"></Setter>
</Style>

And this is my ProgressBar:

<ProgressBar Name="prog" Maximum="100" Value="{Binding Progress}" 
             Width="{Binding Path=Width, ElementName=ProgressCell}" Background="#FFD3D0D0" Style="{StaticResource CustomProgressBar}"/>

But the color hasn't changed.

Verint Verint
  • 557
  • 1
  • 7
  • 19
  • have a look at this already answered question: http://stackoverflow.com/questions/4734814/wpf-progressbar-foreground-color Maybe this works with Windows 7. – dognose Jun 07 '15 at 11:19

2 Answers2

3

At Default, WPF picks system colors(based on OS) if you didn't provide any styles for the controls. If you want to run unique style through out all OS then you have to override styles of the controls and have to merge Styles Xaml to your application For Ex:

 <Style x:Key="ButtonStyle" TargetType="Button">
      <Setter Property="Background" Value="Red"/>
    </Style>

     <Button Style="{StaticResource ButtonStyle}" />
ReeganLourduraj
  • 863
  • 6
  • 9
  • Please see my ProgressBar definition, what i need to change in my case ? – Verint Verint Jun 07 '15 at 11:53
  • you have to override style of the progressbar control not foreground color or background color. It changes only color of the control not style of the control – ReeganLourduraj Jun 07 '15 at 12:06
  • Please see my update, i created new style and add this style into my progress bar but it seems that something is wrong because this is not working. – Verint Verint Jun 07 '15 at 12:16
  • Verint you have to change both styles and templates of progressbar. template for progressbar is vary from one OS to another OS. so you should define a common controltemplate and style then apply those style key to progressbar. – ReeganLourduraj Jun 07 '15 at 12:36
1

It's quite simple, you just need to use your style to modify the Border, PART_Track grid and the rectangle inside (which is the progress portion of the overall control).

Here's an example where I've made the background of the whole thing white, the border black - and the progress part blue:

<Style x:Key="CustomProgressBar" TargetType="ProgressBar" >            
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ProgressBar">
                <Border BorderBrush="Black" BorderThickness="1" Background="White" CornerRadius="0" Padding="0">
                    <Grid x:Name="PART_Track">
                        <Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="Blue" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

This should not vary between Windows 7 or 8!

So with a white background: enter image description here

Or with a green background:

<Border BorderBrush="Black" BorderThickness="1" Background="Green" CornerRadius="0" Padding="0">

enter image description here

James Harcourt
  • 6,017
  • 4
  • 22
  • 42