WPF忽略ProgressBar样式

时间:2010-06-14 12:12:09

标签: wpf templates progress-bar styles

在WPF 4中出现问题,其中默认ProgressBar模板应用了灰白色突出显示,导致前景色变钝,我决定提取模板并手动将值编辑为白色。

执行此操作后,我将模板作为样式放在App.xaml中供全局使用,Visual Studio设计师立即开始使用它。

但是,当我运行我的应用程序时,仍然会应用默认样式:

Top - Application, Bottom - Designer http://www.nidonocu.com/temp_images/progress_problem.png

然后我尝试使用一个键专门设置样式,然后甚至将它作为内联样式,最后作为内联模板,没有特定进度条的包装样式,它仍然被忽略。

出了什么问题?

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

2 个答案:

答案 0 :(得分:1)

我发现了我相信的错误。似乎即使模板是从版本中的构建中提取的。模板中的以下触发器存在某种错误:

<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>

一旦我删除了这个触发器(对视觉效果没有明显影响),模板就开始工作了。

答案 1 :(得分:0)

只是为了确定。您将内部Rectangle绑定到Background属性,而它未在ProgressBar定义中设置(仅Foreground存在)。这是对的吗?

相关问题