WPF中的平滑ProgressBar

时间:2020-03-05 18:58:40  来源:igfitidea点击:

我在WPF应用程序中使用ProgressBar控件,但出现了Windows 3.1 ProgressBlocks这个旧问题。在VB6中,有一个属性可以显示平滑的ProgressBar。 WPF有这样的事情吗?

解决方案

回答

这篇知识库文章似乎解释了我们要寻找的东西...也有指向该文章的VB版本的链接。

回答

我不确定我们要做什么。
如果只想像在启动Vista时那样从一边到另一边"扫描"进度条,则可以使用:IsIndetermined = true。

如果我们实际上希望从0%变为100%,则必须为该值设置动画,如msdn上的此示例所示:http://msdn.microsoft.com/zh-cn/library/system.windows.controls。 progressbar.aspx
或者通过代码隐藏(很可能来自后台工作程序)或者通过绑定到变化的值来显式设置值。

尽管如此,WPF ProgressBar应该始终保持"平滑"状态,UI可能会通过RemoteDesktop连接默认默认为更简单的版本。

回答

在Vista上进行开发后,最近在XP上出现进度条使我感到恼火。我不想尝试从dll加载Vista样式时看到的建议,但是这篇文章给了我我想要的东西。 Vista外观没有新类。另外,它在计时器上有玻璃状的亮点。文章中没有图片,但看起来就像Vista的ProgressBar。

回答

我无法为此找到直接的解决方案。但是我发现了更好的东西。在WPF中,我们可以使用Windows主题。我使用Windows XP,并且在WPF应用程序上安装了Vista-Aero主题,因此所有控件看起来都像Vista-Aero。

这是代码...

转到Application.xaml.vb并写...

Enum appThemes
        Aero
        Luna
        LunaMettalic
        LunaHomestead
        Royale
    End Enum

Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup

        setTheme(appThemes.Aero)

    End Sub

    ''' <summary>
    ''' Function to set the default theme of this application
    ''' </summary>
    ''' <param name="Theme">
    ''' Theme of type appThemes
    ''' </param>
    ''' <remarks></remarks>
    Public Sub setTheme(ByVal Theme As appThemes)

        Dim uri As Uri

        Select Case Theme
            Case appThemes.Aero
                ' Vista Aero Theme
                uri = New Uri("PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\themes/Aero.NormalColor.xaml", UriKind.Relative)

            Case appThemes.Luna
                ' Luna Theme
                uri = New Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\themes/Luna.NormalColor.xaml", UriKind.Relative)

            Case appThemes.LunaHomestead
                ' Luna Mettalic
                uri = New Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\themes/Luna.Metallic.xaml", UriKind.Relative)

            Case appThemes.LunaMettalic
                ' Luna Homestead
                uri = New Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\themes/Luna.Homestead.xaml", UriKind.Relative)

            Case appThemes.Royale
                ' Royale Theme
                uri = New Uri("PresentationFramework.Royale;V3.0.0.0;31bf3856ad364e35;component\themes/Royale.NormalColor.xaml", UriKind.Relative)

        End Select

        ' Set the Theme
        Resources.MergedDictionaries.Add(Application.LoadComponent(uri))

    End Sub

(希望我们可以将其转换为C#)