windows phone 8 - XAML ProgressRing doesn't stop -
my problem progressring running time. use mvvm. progressring active when app new data.
i have code in vm (i updated viewmodel):
public class mainpageviewmodel : observablecollection<admodel>, isupportincrementalloading{ private visibility _loadervisibility; public visibility loadervisibility { { return _loadervisibility; } private set { _loadervisibility = value; }} public iasyncoperation<loadmoreitemsresult> loadmoreitemsasync(uint count) { coredispatcher coredispatcher = window.current.dispatcher; return task.run<loadmoreitemsresult>(async () => { await coredispatcher.runasync(coredispatcherpriority.normal, () => { this.loadervisibility = visibility.visible; }); var newads = new observablecollection<admodel>(); do{newads = await loadads();//get data api} while (newads == null); await coredispatcher.runasync(coredispatcherpriority.normal, () => { foreach (admodel item in newads) { this.add(item); } this.loadervisibility = visibility.collapsed; }); return new loadmoreitemsresult() { count = count }; }).asasyncoperation<loadmoreitemsresult>();}}
first need fire propertychanged
event when change loadervisibility
property, ui can notified of new value. see example on how implement property change notification.
the loadervisibility property should (this vm class needs implement inotifypropertychanged
interface, have propertychanged
event).
private visibility _loadervisibility; public visibility loadervisibility { { return _loadervisibility; } set { _loadervisibility = value; onpropertychanged(new system.componentmodel.propertychangedeventargs("loadervisibility")); } }
second, not set progressring's visibility
property code behind, break data binding wire in xaml.
Comments
Post a Comment