如何在MahApps.Metro ProgressDialog中设置ProgressBarForeground?

时间:2017-09-13 09:34:50

标签: c# wpf mahapps.metro

我想将ProgressDialog内部进度条的颜色更改为HighlightColor。

使用CustomResourceDictionary我设法更改按钮样式但不更改进度条的颜色

    MetroDialogOptions.CustomResourceDictionary = new ResourceDictionary
    {
        Source = new Uri("pack://application:,,,/GUI;component/Styles/DialogDictionary.xaml")
    };

DialogDictionary.xaml:

<Style x:Key="AccentedDialogSquareButton" 
        BasedOn="{StaticResource HighlightedSquareButtonStyle}" 
        TargetType="{x:Type ButtonBase}">
    <Setter Property="Controls:ControlsHelper.ContentCharacterCasing" Value="Normal" />
</Style>

<Style TargetType="{x:Type Dialog:ProgressDialog}" 
                   x:Key="NewProgressDialogStyle" 
                   BasedOn="{StaticResource {x:Type Dialog:ProgressDialog}}">
    <Setter Property="ProgressBarForeground" Value="Red" />
</Style>

<Style TargetType="{x:Type Dialog:ProgressDialog}" 
       BasedOn="{StaticResource NewProgressDialogStyle}" />

1 个答案:

答案 0 :(得分:0)

目前无法做到这一点。

使用SetResourceReference方法将ProgressBarForeground属性设置为本地值,因此使用Setter中的Style无效 - 本地值始终具有优先级高于来自Style的优先级。

您可以尝试覆盖自定义词典中的AccentColorBrush资源,但这不会起作用,因为Mahapps中的当前主题代码将扫描对话框的所有合并资源字典并将此资源替换为特殊的,被定义为&#34;主题强调颜色&#34;。

有关详细信息,请参阅ThemeManager源代码。

您只有两个选择:

  • 将主题的强调颜色更改为所需的进度条颜色(但许多控件将使用此颜色作为其外观)
  • 向Mahapps团队发布变更请求,以便他们可以覆盖ProgressDialog
  • 中的进度条颜色