c# - Updating UI on a UWP (Raspberry Pi / Windows Iot) -
i'm building c# uwp program (using mvvmlight framework) run on raspberry pi running windows 10 iot.
i have method downloads data sql database via wcf connection, can see debugging wcf service working, , data downloads.
i'm puzzled why can call method 2 different ways, 1 updates ui, 1 doesn't. please can explain why?
public class tagregstep2viewmodel : viewmodelbase { private observablecollection<employeename> _employees; private string _onscreeninstructions; public asyncrelaycommand startwizardcommand { get; private set; } public tagregstep2viewmodel() { // initialise messenger messenger.default.register<initialisestepmessage>(this, (msg) => initialisestep(msg.step)); // initialise commands startwizardcommand = new asyncrelaycommand(() => getdata(), () => true); //set dummy default value onscreeninstructions = "default value"; } // can see data downloaded wcf service , observablecollection updates, isn't reflected in ui. public void initialisestep(viewmodelbase vm) { if (vm.gettype() == this.gettype()) { debug.writeline("initialisestep() called"); startwizardcommand.tryexecute(); } } // method retrieves data wcf service. // when called relay command, updates observablecollection , ui. // when called messengercommand updates observablecollection not ui. why??? public async task getdata() { debug.writeline("getting data..."); onscreeninstructions = "loading employees"; await task.delay(25); var emps = await loademployees(); //not posted method, works employees = new observablecollection<employeename>(emps); onscreeninstructions = "please select employee."; await task.delay(25); debug.writeline("observablecollection count :" + employees.count); } public observablecollection<employeename> employees { { return _employees; } set { set(() => employees, ref _employees, value); } } public string onscreeninstructions { { return _onscreeninstructions; } set { set(() => onscreeninstructions, ref _onscreeninstructions, value); } } }
Comments
Post a Comment