c# - WPF, Caliburn Micro Bind Database record to VM -
once again struggling wpf , caliburn micro. want bind db record view if record exists. after retrieving record, view not updated retrieved fields. below similar code using:
view:
<textbox x:name="personid" margin="114,12,288,281" > <i:interaction.triggers> <i:eventtrigger eventname="lostfocus"> <cal:actionmessage methodname="retrieve" /> </i:eventtrigger> </i:interaction.triggers> </textbox> <textbox x:name="firstname" /> <textbox x:name="lastname" />
viewmodel:
[implementpropertychanged] internal class personviewmodel { public string personid { get; set; } public string firstname { get; set; } public string lastname { get; set; } public void retrieve() { try { using (var con = new sqlconnection(constr)) { var q = con.query<personviewmodel>("select firstname,lastname person id = @id", new {id = personid}).first(); messagebox.show("succesfully retrieved " + q.firstname + " " + q.lastname); } } catch (exception x) { console.writeline("error retrieving due {0}", x.message); } }
}
the retrieve
method firing , getting results in messagebox
. view not updated. missing anything?
your data retrieved database q
. need copy data personid
, firstname
etc properties. when update properties, property changed notification update view.
something this:
public void retrieve() { try { using (var con = new sqlconnection(constr)) { var q = con.query<personviewmodel>("select firstname,lastname person id = @id", new {id = personid}).first(); // copy database data local properties update view... this.personid = q.personid; this.firstname = q.firstname; ... messagebox.show("succesfully retrieved " + q.firstname + " " + q.lastname); } } catch (exception x) { console.writeline("error retrieving due {0}", x.message); } }
Comments
Post a Comment