[英]WPF C# Circle Progress Bar WindowsFormsHost
So I'm getting a weird error... I followed some steps to create a CircularProgressBar in my WPF C# App. 所以我收到一个奇怪的错误...我按照一些步骤在WPF C#应用程序中创建了一个CircularProgressBar。 It works fine on my desktop, it doesn't on my laptop.
它可以在台式机上正常工作,而不能在笔记本电脑上工作。
I create a WindowsFormsHost and make the Circular Progress Bar the Child. 我创建一个WindowsFormsHost并将“循环进度栏”作为子级。 I then make it the children of a grid called ProgressGrid.
然后,我将其作为名为ProgressGrid的网格的子级。
Anyway, The error just says "Unhandled exception has occured in a component in your application. If you click Continue, the application will ignore this error" It runs perfectly fine if I click continue mind you. 无论如何,该错误仅表示“您的应用程序中的组件中发生了未处理的异常。如果单击“继续”,则应用程序将忽略此错误”。如果我单击“继续”,请注意。
The error details say "System.ArgumentException: Parameter is not valid" it goes on to list pretty much everything I wrote. 错误详细信息显示“ System.ArgumentException:参数无效”,它继续列出我编写的几乎所有内容。 I thought it had something to do with Dispose()... Heres the Code:
我认为这与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
For now the gridjust displays a string as the number while I adjust things so you can ignore that. 现在,当我调整内容时,gridjust将字符串显示为数字,因此您可以忽略它。 I also read something about GDI but I'm a bit lost.
我也读了一些有关GDI的内容,但我有点迷茫。
PS I should note it also says "Invalid Parameter" which it most certainly is not. PS我应该注意它也说“无效的参数”,它肯定不是。
PPS I developed this on a Windows 7 64 bit. PPS我是在Windows 7 64位上开发的。 My laptop is a Windows 10 64bit.
我的笔记本电脑是Windows 10 64位。 But it also doesn't work on my brothers Windows 7 64 bit.
但这在我的兄弟Windows 7 64位上也不起作用。 If that helps any...
如果有帮助...
Okay, so I was able to make it work. 好的,所以我能够使它工作。 I'm not "exactly" sure why though.
我不确定“为什么”。 I loaded the grid that contains the WindowsFormsHost Grid with visibility set to false first and after it loaded I set it to true.
我加载了包含WindowsFormsHost网格的网格,该网格的可见性首先设置为false,然后在加载后将其设置为true。 For whatever reason, it works this way.
无论出于何种原因,它都以这种方式工作。 If anyone could think of why that would be awesome.
如果有人能想到为什么会很棒。 This way does work though!
这种方式确实有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.