Mvvm Light Dispatcher Helper -
how can use dispatcher helper progress bar in mvvm-light. i'm accessing ui element defined in viewmodel , think dispatcherhelper solved this, seems progressbar not updated when ran backgroundworker dispatcherhelper. please help:
here's code :
_worker = new backgroundworker() { workerreportsprogress = true, workersupportscancellation = true }; _grid = new grid(); _worker.dowork += (sender,e) => dispatcherhelper.uidispatcher.invoke(() => { try{ var vworker = (backgroundworker) sender; reportcolumns = new list<reportcolumn>(); #region set report item column for(var = 1;i <= _reportbal.reportitemcontent.columns.count - 1;i++) { var vcolumnsitems = reportparser.parsecolumnattributes(_reportbal.reportitemcontent.columns[i].columnname); var vcolumn = new reportcolumn(); vcolumn.datatype = vcolumnsitems[0]; vcolumn.width = vcolumnsitems[1]; vcolumn.header = vcolumnsitems[2]; vcolumn.datafield = vcolumnsitems[2]; reportcolumns.add(vcolumn); } if(reportcolumns != null) { for(int ctrcol = 0;ctrcol <= reportcolumns.count - 1;ctrcol++) { var sp = new stackpanel { orientation = orientation.horizontal }; _grid.columndefinitions.add(new columndefinition { width = new gridlength(convert.todouble(reportcolumns[ctrcol].width)) }); var tb = new textblock { text = reportcolumns[ctrcol].datafield, fontweight = fontweights.demibold, margin = new thickness(8,0,8,0), textwrapping = textwrapping.wrap }; sp.children.add(tb); grid.setrow(sp,0); grid.setcolumn(sp,ctrcol); _grid.children.add(sp); } } #endregion #region set report item row gridhelper.setrowcount(_grid,_reportbal.reportitemcontent.rows.count + 1); for(int rrow = 0;rrow <= _reportbal.reportitemcontent.rows.count - 1;rrow++) { if(vworker.cancellationpending) { e.cancel = true; break; } for(int ccol = 0;ccol <= reportcolumns.count - 1;ccol++) { string vvalue = _reportbal.reportitemcontent.rows[rrow][ccol + 1].tostring(); ; var sp = new stackpanel { orientation = orientation.horizontal }; var tb = new textblock { text = vvalue, width = double.parse(reportcolumns[ccol].width), margin = new thickness(8,3,8,3), textwrapping = textwrapping.wrap }; sp.children.add(tb); grid.setcolumn(sp,ccol); grid.setrow(sp,rrow + 1); _grid.children.add(sp); } if(vworker.workerreportsprogress) { _recordcount = _reportbal.reportitemcontent.rows.count; int vpercentcomplete = (int)((float)rrow / (float)_recordcount * 100); string updatemessage = string.format("record(s) {0} of {1}",rrow,_recordcount); vworker.reportprogress(vpercentcomplete,updatemessage); } } #endregion e.result = _grid; //_reportitemcontent = _grid; } catch(exception exception) { throw new exception("#error: error parsing report items" + environment.newline + environment.newline + "#internal error: " + exception.message,exception); } }); _worker.progresschanged += (s,e) => dispatcherhelper.runasync((() =>{ progresspercentage = e.progresspercentage; output = (string)e.userstate; })); _worker.runworkercompleted += (s,e) => /*dispatcherhelper.uidispatcher.invoke((() =>*/ { if(e.error != null) throw new exception("error tae"); _reportitemcontent = (grid)e.result; };
Comments
Post a Comment