c# - Change WPF DataTemplate for one entry change -
in wpf app, i've written mouse double click event listbox entries. when double click on single entry, posted on server. problem is, when post entry server, want change datatemplate of entry only. in below code i've written, posted entries server. so, please suggest ways change datatemplate single entry only. "harvest_timesheetentry" listbox entry.
also see comments in code.
c# code:
private void listbox1_mousedoubleclick(object sender, mousebuttoneventargs e) { //submit clicked entry if (sender listboxitem) { listboxitem item = (listboxitem)sender; harvest_timesheetentry entrytopost = (harvest_timesheetentry)item.datacontext; if (!entrytopost.issynced) { //check if selected in selectedclientitem , selectedprojectitem items if (entrytopost.clientnamebinding == "select client" || entrytopost.projectnamebinding == "select project") system.windows.messagebox.show("please select project , client"); else { globals._globalcontroller.harvestmanager.postharvestentry(entrytopost); system.windows.messagebox.show("entry posted"); datatemplate tmpl = (datatemplate)this.findresource("defaultdatatemplate"); listbox1.itemtemplate = tmpl; // **here want change datatemplate posted entry.** } } else { //already synced.. make noise or system.windows.messagebox.show("already synced;todo play sound instead"); } } }
try using following line in replacement of line:
harvest_timesheetentry entrytopost = (harvest_timesheetentry)item.content; this access data item inside listboxitem. of course depends on how have set datacontext of items... i'm assuming have set datacontext of listbox.itemssource , not on each listboxitem. note if have set datacontext of each listboxitem, that problem.
Comments
Post a Comment