windows phone 8 - ContextMenu selects old item -
so situation. have longlistselector
shows data (say, list of cars):
<phone:longlistselector x:name="list" itemssource="{binding carlist}"> <phone:longlistselector.itemtemplate> <datatemplate> <stackpanel> <toolkit:contextmenuservice.contextmenu> <toolkit:contextmenu> <toolkit:menuitem click="deletemenuitem_click" header="delete"/> </toolkit:contextmenu> </toolkit:contextmenuservice.contextmenu> <textblock text="{binding sometext}"> </stackpanel> </datatemplate> </phone:longlistselector.itemtemplate> </phone:longlistselector>
and how handle deletion:
private void deletemenuitem_click(object sender, routedeventargs e) { car data = (sender menuitem).datacontext car; using (var db = new sqliteconnection(app.dbpath)) { var existing = db.query<feed>("select * cars id = " + data.id.tostring()).firstordefault(); if (existing != null) { db.runintransaction(() => { db.delete(existing); }); app.viewmodel.loadcardata(); } } }
now issue after deleting few, context menu starts give old selection , not update makes var existing = db.query<feed>("select * cars id = " + data.id.tostring()).firstordefault();
return null because has been deleted database. idea how fix this?
probably this issue.
private void contextmenu_unload(object sender, routedeventargs e) { contextmenu conmen = (sender contextmenu); conmen.clearvalue(frameworkelement.datacontextproperty); }
Comments
Post a Comment