WPF uses backgroundworker to dynamically load the UI

Source: Internet
Author: User
Backgroundworker BW = new backgroundworker (); BW. dowork + = (EE, SE) =>{// todo requires asynchronous request operations}; BW. runworkercompleted + = (EW, SW) => {dispatcher. invoke (new action () =>{ <span style = "white-space: pre"> </span> // todo dynamically generated UI}) ;}; BW. runworkerasync ();


Demo:

List <resourceindex> coursewarelist = new list <resourceindex> (); // courseware list <resourceindex> teachingplanlist = new list <resourceindex> (); // teaching plan list <resourceindex> exerciseslist = new list <resourceindex> (); // exercise list <resourceindex> materiallist = new list <resourceindex> (); // material list <resourceindex> reslist = new list <resourceindex> (); string bookcode = ebookcontext. instance. currentbook. indexinfo. code; string unitcode = ebookcontext. instance. currentunit. unitcode; backgroundworker BW = new backgroundworker (); BW. dowork + = (EE, SE) =>{ reslist = searchresource (bookcode, unitcode); foreach (resourceindex resindex in reslist) {Switch (resindex. usage) {Case resourceusage. courseware: coursewarelist. add (resindex); break; Case resourceusage. techingdesign: teachingplanlist. add (resindex); break; Case resourceusage. testquestion: exerciseslist. add (resindex); break; Case resourceusage. teachmaterial: materiallist. add (resindex); break; default: Break ;}}; BW. runworkercompleted + = (EW, SW) => {dispatcher. invoke (new action () => {clearresource (); this. onloading. visibility = visibility. collapsed; If (coursewarelist. count> 0) {resdetailcontainer resc1 = new resdetailcontainer ("courseware", "# ff48b95a", coursewarelist); this. rescontainer. children. add (resc1);} If (teachingplanlist. count> 0) {resdetailcontainer resc2 = new resdetailcontainer ("Teaching Plan", "# fffb5454", teachingplanlist); this. rescontainer. children. add (resc2);} If (exerciseslist. count> 0) {resdetailcontainer resc3 = new resdetailcontainer ("exercises", "# ff3e80da", exerciseslist); this. rescontainer. children. add (resc3);} If (materiallist. count> 0) {resdetailcontainer resc4 = new resdetailcontainer ("clip", "# ffe7b01b", materiallist); this. rescontainer. children. add (resc4);} If (reslist. count = 0) {This. nores. visibility = visibility. visible ;}}) ;}; BW. runworkerasync ();



WPF uses backgroundworker to dynamically load the UI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.