task - Show RadBusyIndicator during Frame Navigation WPF -
for our application, need display busy indicator during navigation since controls taking time load. long running operation create separate task , trigger busy indicator in ui thread in case couldn't that.
once busy indicator started spin, got disturbed frame.source or frame.navigate executes in ui thread. busy indictor hidden away .
the below piece of code have used navigation. executed separate task .
public virtual void navigateto(string pagekey, object parameter) { frame frame = null; action actiontoexecuteonuicontext = () => { frame = getdescendantfromname(application.current.mainwindow, "contentframe") frame; if (frame != null) { frame.loadcompleted -= frame_loadcompleted; frame.loadcompleted += frame_loadcompleted; frame.source = _pagesbykey[pagekey]; frame.datacontext = parameter; } }; application.current.dispatcher.begininvoke(actiontoexecuteonuicontext, dispatcherpriority.normal); } }
any way fix or alternative
wpf & radbusyindicator & .net 4.5
in order display busy indicater have use background thread, because navigation needs ui thread.
i suggest use :
protected async void navigation(string pagekey, object parameter) { await navigateto(pagekey,parameter).continuewith((t) => {// ui stuff dispatcher.currentdispatcher.invokeasync(delegate { isbusy = false; }); }, //sync ui thread taskscheduler.fromcurrentsynchronizationcontext()); } /// <summary> /// method needs async perform async binding /// </summary> /// <param name="value"></param> /// <returns></returns> private async task navigateto(string pagekey, object parameter) { //your async method }
where isbusy value of busyindicator. have set true, on navigation started.
hope post you@!
Comments
Post a Comment