c# - How to use Progressbar in MVVM -
i'm stuck on this. searched lot in net nothing helped me. in view have 1 button , progressbar, when user click on button different work , after increase currentprogress.
but shows user in end of work 100% in end , not want. eachtime currentprogress increased shows , display view.
the controls in view those:
<button x:name="generate" content="generate" /> <progressbar value="{binding path=currentprogress, mode=oneway}" width="80" height="15"/>
and code in viewmodel
private int currentprogress; public int currentprogress { { return currentprogress; } set { if (currentprogress == value) return; currentprogress = value; notifyofpropertychange(() => currentprogress); } } list<article> articles; public void generate() { foreach (var art in articles) { //[..] //insert article inserted++; task.factory.startnew(() =>updateprogress(inserted)); } } private void updateprogress(int analyzed) { if (analyzed != 0) { int percentage = 100 * analyzed / articles.count; currentprogress = percentage; } }
how fix issue?. in advance!
put whole content of "generate" method inside task. don't need special update progress since "notifypropertychanged" events automatically marshalled @ ui level wpf. this:
task.factory.startnew(() => { foreach (var art in articles) { //[..] //insert article inserted++; updateprogress(inserted); } }
Comments
Post a Comment