Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: why my foreground color looks difference under different OS

Tags:

wpf

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.

like image 694
Verint Verint Avatar asked Sep 27 '22 17:09

Verint Verint


2 Answers

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}" />
like image 156
ReeganLourduraj Avatar answered Dec 31 '22 20:12

ReeganLourduraj


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

like image 35
James Harcourt Avatar answered Dec 31 '22 21:12

James Harcourt