c# - Universal Apps using Unity & Prism -


i learning whole new universal apps creation prism , unity, got few questions not sure about:

i have following simple data object:

public class customer : ieditableobject, iequatable<customer> {     private customer backup;     public string name { get; set; }     public string surname { get; set; }     public datetime dateofbirth { get; set; }      public void beginedit()     {         this.backup = this.memberwiseclone() customer;     }      public void canceledit()     {         this.name = this.backup.name;         this.surname = this.backup.surname;         this.dateofbirth = this.backup.dateofbirth;     }      public void endedit()     {         this.backup = this.memberwiseclone() customer;     }      public bool waschangemade()     {         if (this.equals(backup))             return false;         else             return true;     }      public bool equals(customer other)     {         return this.name == other.name &&             this.surname == other.surname &&             this.dateofbirth == other.dateofbirth;     } } 

under main page have simple listbox, show collection of these customers. far.

afterwards, when under listbox user selects 1 of these customer, can click edit settings button , edit properties of selected customer. simple command:

        cmd_editcustomer = new delegatecommand(() =>         {             _navigationservice.navigate(app.experiences.detail.tostring(), selectedcustomer);         }); 

which navigates new page (detail page, user can changes) , argument pass here selected customer.

my detailpage view model looks following:

public class detailpageviewmodel : viewmodel, interfaces.idetailpageviewmodel {     public delegatecommand cmd_savechanges { get; set; }     public customer selectedcustomer { get; set; }      private readonly inavigationservice _navigationservice;     private readonly idialogservice _dialogservice;     public detailpageviewmodel(inavigationservice navigationservice,         idialogservice dialogservice)     {         _navigationservice = navigationservice;         _dialogservice = dialogservice;          initializecommands();     }      public override void onnavigatedto(object navigationparameter, navigationmode navigationmode, dictionary<string, object> viewmodelstate)     {         this.selectedcustomer = navigationparameter customer;         this.selectedcustomer?.beginedit();     }      private void initializecommands()     {         cmd_savechanges = new delegatecommand(() =>         {             selectedcustomer?.endedit();             _dialogservice.show("changes saved!");             _navigationservice.navigate(app.experiences.main.tostring(), null);         });     } } 

as can see, simple application, use learning purposes. here questions:

1) pass selected customer in such way did? (in parameter of inavigationservice), or should implement other logic?

2) when user makes change selected customer , clicks save changes (the command can see there), not update original customer (from original collection). how possible? how achieve, customer updated? should create pubsubevent this?

edit:

i have managed locate error - when user navigates mainpage, mainpageviewmodel re-initializes, re-populates collection of items. question - how can keep mainwindowviewmodel alive thorough applications life?

re-populates collection of items what?

you need save new values, example if populate customers db have call db , save changes before navigate etc, after when mainpageviewmodel re-initializes you'll changes , changes performed users.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -