2010-06-14 83 views
0

继WPF 4中的默认ProgressBar模板应用了灰白色突出显示的问题导致它变暗前景色之后,我决定提取模板并手动将值编辑为白色。WPF忽略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}" /> 
        ... 
+0

'“{TemplateBinding Panel.Background}”'你确定你是绑定到面板的背景吗? – Amsakanna 2010-06-14 12:51:59

+0

这是原始模板的一部分并且正确工作(在VS设计器中)。问题是整个模板在运行时没有显示出来。 – Nidonocu 2010-06-14 13:00:21

回答

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> 

只要我删除该触发器(这对视觉效果没有明显的影响)的模板开始工作。

0

只是可以肯定。您将内部矩形绑定到Background属性,而未在ProgressBar定义中设置它(只有Foreground在那里)。那是对的吗?

+0

这是原始模板中定义的进度条的背景。 – Nidonocu 2010-06-14 13:01:11