Nidonocu
Nidonocu

Reputation: 12618

WPF Ignoring ProgressBar Style

Following a problem in WPF 4 where the default ProgressBar template has an off-white highlight applied causing it to dull the foreground colour, I decided to extract the template and manually edit the values to white.

After doing this, I put the template as a style in App.xaml for global use and the Visual Studio designer began to use it right away.

However, when I run my app, the default style is still being applied:

Top - Application, Bottom - Designer
(source: nidonocu.com)

I then tried setting the style specifically using a key, then even having it as an inline style and finally as a inline template without a wrapping style for the specific progress bar and it is still ignored.

What's going wrong?

Current code for the ProgressBar:

 <ProgressBar Grid.Column="1"
              Grid.Row="2"
              Height="15"
              Width="355"
              Margin="0,0,0,7"
              IsIndeterminate="{Binding ProgressState, FallbackValue=False}"
              Visibility="{Binding ProgressVisibility, FallbackValue=Collapsed}"
              Value="{Binding ProgressValue, Mode=OneWay, FallbackValue=100}"
              Foreground="{Binding ProgressColor,FallbackValue=Red}">
        <ProgressBar.Template>
            <ControlTemplate>
                <Grid Name="TemplateRoot"
                      SnapsToDevicePixels="True">
                    <Rectangle RadiusX="2"
                               RadiusY="2"
                               Fill="{TemplateBinding Panel.Background}" />
                    ...

Upvotes: 0

Views: 1358

Answers (2)

Nidonocu
Nidonocu

Reputation: 12618

I've found the error I believe. It seems that even though the template was extracted from the build in version. There was some kind of error with the following trigger in the template:

<Trigger Property="ProgressBar.IsIndeterminate">
    <Setter Property="Panel.Background"
            TargetName="Animation">
        <Setter.Value>
            <SolidColorBrush>#80B5FFA9</SolidColorBrush>
        </Setter.Value>
    </Setter>
    <Trigger.Value>
        <s:Boolean>False</s:Boolean>
    </Trigger.Value>
</Trigger>

As soon as I removed this trigger (which had no visible impact on the visuals) the template began to work.

Upvotes: 1

Anvaka
Anvaka

Reputation: 15823

Just to be sure. You are binding internal Rectangle to the Background property, while it's not set in the ProgressBar definition (only Foreground is there). Is that correct?

Upvotes: 0

Related Questions