WPF中平滑的进度条

6

我在WPF应用程序中使用ProgressBar控件,但是它显示的是Windows 3.1风格的进度块。在VB6中,有一个属性可以显示平滑的ProgressBar。在WPF中是否有这样的属性?


不是答案,但关于进度条和平滑操作的话题,这里有一篇关于不同功能的好论文:http://www.chrisharrison.net/projects/progressbars/ProgBarHarrison.pdf - Tom Ritter
4个回答

4
这篇文章似乎解释了你所需要的内容...还有一个链接可以提供VB版本的文章。

哦,至少它说:“你不能再这样做了!”不幸的是,解决方案本身有点过于简约 - 我严重怀疑它能否与动画一起使用。不过还是谢谢你。 - Daren Thomas
这是一个WinForms解决方案。在WPF中,您应该为ProgressBar创建一个新的ControlTemplate。 - Abe Heidebrecht

2

我没有找到直接的解决方案,但我发现了更好的方法。在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#代码。


0

我不确定你想做什么。 如果你只是想要一个像启动Vista时从一侧到另一侧“扫过”的进度条,你可以使用:IsIndetermined = true。

如果你真的想从0%到100%,你必须要么像msdn上的这个例子中所示动画显示值http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar.aspx,要么在代码后台(最可能是从后台工作者)显式设置值,或者通过绑定到一个变化的值来设置值。

尽管WPF ProgressBar应该始终是“平滑”的,但在远程桌面连接中,UI可能会默认为更简单的版本。


0

最近我在XP上开发时,对进度条的外观感到很烦恼,因为我是在Vista上进行开发的。我不想尝试从dll中加载Vista样式的建议,但this article给了我我想要的东西。它提供了Vista外观-没有新类。此外,它还有一个定时器上的玻璃高亮显示。文章中没有图片,但它看起来就像Vista的ProgressBar。


获取ProgressBarExamples.zip,在Window1.xaml中有一个styleProgressBarVista,您可以将其提取到您的xaml中或ResourceDictionary中。 - Thomas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接