WPF C# 圆形进度条 WindowsFormsHost

WPF C# Circle Progress Bar WindowsFormsHost

所以我遇到了一个奇怪的错误...我按照一些步骤在我的 WPF C# 应用程序中创建了一个 CircularProgressBar。它在我的台式机上运行良好,但在我的笔记本电脑上运行不正常。

我创建了一个 WindowsFormsHost 并将循环进度条设为子对象。然后,我将其设为名为 ProgressGrid 的网格的子项。

无论如何,错误只是说 "Unhandled exception has occured in a component in your application. If you click Continue, the application will ignore this error" 请注意,如果我单击“继续”,它会运行得很好。

错误详细信息说 "System.ArgumentException: Parameter is not valid" 它继续列出我写的几乎所有内容。我认为它与 Dispose() 有关...这是代码:

        var SelectAll =
            (from a in dc.GetTable<SR>()
             select a).ToList();
        int all = SelectAll .Count();

        var ByGroup =
            (from a in dc.GetTable<SR>()
             where a.GroupID == GroupID
             orderby a.ID
             select a).ToList();
        int SelectedGroup = ByGroup .Count();

        System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();


        CircularProgressBar.CircularProgressBar ProgressCircle = new CircularProgressBar.CircularProgressBar();


        host.Child = ProgressCircle;


        ProgressGrid.Children.Add(host);

        if (ShallMarquee == 1 || FilterByThisDivision == TheEmployee.Division)
        {
            ProgressCircle.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
        }
        else
        {
            ProgressCircle.Style = System.Windows.Forms.ProgressBarStyle.Blocks;
        }

        ProgressCircle.MarqueeAnimationSpeed = 4000;
        ProgressCircle.Text = Convert.ToString(NumOf + "%");
        ProgressCircle.SubscriptText = "";
        ProgressCircle.SuperscriptText = "";
        ProgressCircle.Font = new Font("Arial", 22);
        ProgressCircle.ProgressWidth = 10;
        ProgressCircle.SuperscriptColor = System.Drawing.Color.Black;
        ProgressCircle.ProgressColor = System.Drawing.ColorTranslator.FromHtml(MainColor);
        System.Windows.Media.Color StandardBackgroundBlue = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(BackgroundColor);
        var drawingcolor = System.Drawing.Color.FromArgb(StandardBackgroundBlue.A, StandardBackgroundBlue.R, StandardBackgroundBlue.G, StandardBackgroundBlue.B);
        ProgressCircle.BackColor = drawingcolor;
        ProgressCircle.InnerColor = drawingcolor;
        ProgressCircle.OuterColor = System.Drawing.Color.LightGray;

        ProgressCircle.ForeColor = System.Drawing.Color.Black;
        ProgressCircle.Value = NumOf;
        ProgressCircle.Maximum = TotalNum;
        //END CIRCLE

现在网格只显示一个字符串作为数字,而我调整了一些东西,所以你可以忽略它。我也读过一些关于 GDI 的东西,但我有点迷路了。

P.S。我应该注意到它还说 "Invalid Parameter" 但它肯定不是。

P.P.S。我在 Windows 7 64 位上开发了这个。我的笔记本电脑是 Windows 10 64 位。但它也不适用于我的兄弟 Windows 7 64 位。如果有帮助...

好的,所以我能够让它发挥作用。我不确定 "exactly" 为什么。我加载了包含 WindowsFormsHost 网格的网格,首先将可见性设置为 false,然后在加载后将其设置为 true。无论出于何种原因,它都是这样工作的。如果有人能想到为什么那会很棒。不过这种方式确实有效!