C# WPF 中的平滑进度条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/82365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 11:20:31  来源:igfitidea点击:

Smooth ProgressBar in WPF

提问by Daren Thomas

I'm using the ProgressBar control in a WPF application and I'm getting this old, Windows 3.1 ProgressBlocksthing. In VB6, there was a property to show a smoothProgressBar. Is there such a thing for WPF?

我在 WPF 应用程序中使用 ProgressBar 控件,并且我得到了这个旧的 Windows 3.1 Progress Blocks东西。在 VB6 中,有一个属性可以显示平滑的ProgressBar。WPF有这样的事情吗?

采纳答案by xan

ThisKB article seems to explain what you are looking for... there is a link to a VB version of the article too.

这篇知识库文章似乎解释了您要查找的内容……还有指向该文章的 VB 版本的链接。

回答by GaussZ

I am not sure what you want to do. If you simply want a progress bar that "sweeps" from side to side like on starting Vista you could use: IsIndetermined = true.

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

If you actually want to go from 0% to 100% you have to either animate over the value as shown in this example on msdn: http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar.aspxor set the value explicitly either in code-behind (most likely from a background worker) or through a binding to a changing value.

如果您确实想要从 0% 到 100%,您必须对值进行动画处理,如 msdn 上的此示例所示:http: //msdn.microsoft.com/en-us/library/system.windows.controls。 progressbar.aspx或在代码隐藏中(很可能来自后台工作人员)或通过绑定到变化的值显式设置值。

Nevertheless the WPF ProgressBar should always be "smooth", there is the possibility that the UI will default to a more simpler version through a RemoteDesktop connection.

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

回答by Thomas

I recently was annoyed by the appearance of my progress bars on XP after developing on Vista. I didn't want to try suggestions I'd seen for loading the Vista styles out of dll's, but this articlegave me just what I was looking for. vista appearance - no new classes. Plus it has the glassy highlight on a timer. No pictures on the article, but it looks just like Vista's ProgressBar.

我最近对在 Vista 上开发后在 XP 上出现的进度条感到恼火。我不想尝试从 dll 中加载 Vista 样式的建议,但是这篇文章给了我我正在寻找的东西。远景外观 - 没有新课程。此外,它在计时器上具有玻璃般的亮点。文章上没有图片,但它看起来就像Vista的ProgressBar。

回答by Thomas

I was not able to find a direct solution for this. But I found something even better. In WPF, you can use Windows Themes. I am using Windows XP, and having Vista-Aero Theme on my WPF Application, making all controls look like Vista-Aero.

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

Here's the code...

这是代码...

Go to Application.xaml.vb and write...

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

(I hope you can convert it to C#)

(我希望你能把它转换成 C#)