Verint Verint
Verint Verint

Reputation: 567

WPF: why my foreground color looks difference under different OS

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.

Upvotes: 5

Views: 408

Answers (2)

James Harcourt
James Harcourt

Reputation: 6379

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

Upvotes: 1

ReeganLourduraj
ReeganLourduraj

Reputation: 873

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}" />

Upvotes: 3

Related Questions