WPF:UI元素不更新

WPF:UI元素不更新,第1张

概述WPF:UI元素不更新

我有一个BackgrounDWorker,并在该工作人员,我正在从Excel文件中读取数据。 如果excel文件中有错误,工作人员完成,然后显示另一个表单,用户可以input更正,然后按OK键,然后从头开始再次运行工人。 当工作人员成功完成时,应该更新我的主窗口上的标签,说它已经加载了Excel。 但标签不会更新。 当我deBUGging它时,我可以看到更新标签运行的代码,但它根本不起作用。 请帮忙,这让我疯狂!

这是我的代码。

private voID worker_ReadfileData(object sender,DoWorkEventArgs e) { for (int j = 1; j < rcount + 1; j++) { worker.ReportProgress(j); // Do work if (j == 1) { ColumnIndex column = this.ValIDateColumnIndexes(tableType); if (column != null) { // If error in file,complete worker fileData.isDataLoaded = false; e.Result = fileData; return; } } } fileData.isDataLoaded = true; e.Result = fileData; // Pass the data to the completed method. } private voID worker_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e) { if (e.Error != null) { } else if (e.Cancelled) { } else { fileData fileData = (fileData) e.Result; if (fileData.isDataLoaded == true) { testLabel.Content = "It works!"; } else { // Show Dialog where user can input the correction ColumnIndexPrompt columnIndexPrompt = new ColumnIndexPrompt(fileData.filePath,fileData.fileExtension,fileData.tableType,fileData.Column); columnIndexPrompt.ShowDialog(); } } } public voID TriggerReadDatafile(string filePath,string fileExt,int tableType) { progbar.Value = 0; // Read the file data and populate the Registrars List,then show the datagrID worker.RunWorkerAsync(new fileData(filePath,fileExt,tableType)); }

编辑:这是从第二个窗口,我打开的代码(在上面的代码中使用.ShowDialog())

public ColumnIndexPrompt(string filePath,int tableType,ColumnIndex column) { InitializeComponent(); this.filePath = filePath; this.fileExt = fileExt; this.tableType = tableType; this.column = column; lblColumnIndexErrorMsg.Text = column.ErrorMsg; } private voID btnColumnIndexApply_Click(object sender,RoutedEventArgs e) { MainWindow originalForm = new MainWindow(); int correctColumnNumber = int.Parse(txtColumnIndexCorrection.Text); column.Index = correctColumnNumber - 1; originalForm.UpdateSingleColumnIndex(column); originalForm.TriggerReadDatafile(this.filePath,this.fileExt,this.tableType); this.Close(); }

使用windows事件日志有哪些选项?

你能全屏运行一个VB应用程序吗?

修改创builddate的属性

Winform应用程序在XP系统上闪烁

是否有可能从另一个进程捕获“找不到文件”,然后将文件返回到该进程?

在开发过程中发送testing电子邮件,无垃圾邮件或拒绝问题

为.NET程序提供输出types的windows应用程序和控制台应用程序

如何获取调用过程windows用户访问令牌

未处理的exception导致应用程序崩溃与“EventType clr20r3,P1 w3wp.exe”在日志中,但没有详细信息

使用C#获取连接到命名pipe道服务器的客户端的进程ID

您正在创建MainWindow对象,只需将其更改为:

MainWindow mainWindow = Application.Current.MainWindow;

这里:

private voID btnColumnIndexApply_Click(object sender,RoutedEventArgs e) { MainWindow originalForm = (MainWindow)Application.Current.MainWindow; //here int correctColumnNumber = int.Parse(txtColumnIndexCorrection.Text); column.Index = correctColumnNumber - 1; originalForm.UpdateSingleColumnIndex(column); originalForm.TriggerReadDatafile(this.filePath,this.tableType); this.Close(); }

总结

以上是内存溢出为你收集整理的WPF:UI元素不更新全部内容,希望文章能够帮你解决WPF:UI元素不更新所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1278468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存