c# - Binding a ListBox to a List<string> -
i trying bind list of strings contents of list box. reason, results bluetape list, contents of bluetapelist not ever make listbox. appreciated!
xaml:
<listbox name="lbxtapein" grid.row="1" grid.column="1" grid.columnspan="1" width="70" height="80" selectionchanged="tapeselectionchanged" itemssource="{binding}" selectedvalue="{binding selectedbt}" background="deepskyblue" foreground="midnightblue" horizontalalignment="center" verticalalignment="center" margin="5"/>
code behind:
public partial class overrideaoibinningwindow : window { private overrideaoibinningwindowviewmodel ovaoibinwin; public overrideaoibinningwindow() { initializecomponent(); ovaoibinwin = new overrideaoibinningwindowviewmodel(tvwwaferlist, txtfilter); assigndatacontexts(); } private void assigndatacontexts() { btnchoosewafer.datacontext = ovaoibinwin; btnsave.datacontext = ovaoibinwin; txtwafer.datacontext = ovaoibinwin; cbxaoistate.datacontext = ovaoibinwin; lbxtapein.datacontext = ovaoibinwin.bluetapelist; } private void tapeselectionchanged(object sender, routedeventargs e) { if (!string.isnullorempty(ovaoibinwin.selectedwafer)) { if (cbxaoistate.selectedvalue != null) { btnsave.isenabled = true; } } } private void aoistatechanged(object sender, routedeventargs e) { if (!string.isnullorempty(ovaoibinwin.selectedwafer)) { if (lbxtapein.selectedvalue != null) { btnsave.isenabled = true; } } } private void close(object sender, routedeventargs e) { this.close(); } }
view model:
public class overrideaoibinningwindowviewmodel : viewmodelbase, iselectwafers { public overrideaoibinningwindowviewmodel(treeview tvwwaferlist, textbox txtfilter) { // set private fields this.tvwwaferlist = tvwwaferlist; this.txtfilter = txtfilter; // instantiate objects , initialize settings this.instantiateobjects(); this.setcontrolsettings(); // run initialization thread initthread.runworkerasync(); } public string selectedwafer { { return selectedwafer; } set { selectedwafer = value; onpropertychanged("selectedwafer"); } } public string selectedbt { { return selectedbt; } set { selectedbt = value; onpropertychanged("selectedbt"); } } public string selectedaoistate { { return selectedaoistate; } set { selectedaoistate = value; onpropertychanged("selectedaoistate"); } } public list<string> aoistatelist { { return aoistatelist; } set { aoistatelist = value; onpropertychanged("aoistatelist"); } } public list<string> bluetapelist { { return bluetapelist; } set { bluetapelist = value; onpropertychanged("bluetapelist"); } } public icommand selectwafercommand { { if (selectwafercommand == null) { selectwafercommand = new delegatecommand(selectwafer); } return selectwafercommand; } } public icommand saveaoistatecommand { { if (saveaoistatecommand == null) { saveaoistatecommand = new delegatecommand(saveaoistate); } return saveaoistatecommand; } } private void instantiateobjects() { initthread = new backgroundworker(); aoistatelist = new list<string>(); bluetapelist = new list<string>(); converter = new waferidconverter(); } private void setcontrolsettings() { initthread.workerreportsprogress = false; initthread.workersupportscancellation = false; initthread.dowork += initthread_dowork; initthread.runworkercompleted += initthread_runworkercompleted; } private void populateaoistatelist() { aoistatelist.add("true"); aoistatelist.add("false"); aoistatelist.add("notbinned"); aoistatelist.add("neveraoi"); } private void populatebluetapelist() { waferqueries = new waferqueries( datalibrary.getsingulationone(selectedwafer)); foreach (bluetape tape in waferqueries.getbluetapelist()) { bluetapelist.add(tape.name); } onpropertychanged("bluetapelist"); } private void saveaoistate() { mouse.overridecursor = cursors.wait; singone = new singonetable(); singone.overrideaoistate(selectedwafer, selectedbt, selectedaoistate); mouse.overridecursor = null; messagebox.show( "the aoi state of " + selectedbt + " " + selectedwafer + " has been changed " + selectedaoistate + "!", "aoi state saved", messageboxbutton.ok, messageboximage.exclamation); } public void selectwafer() { mouse.overridecursor = cursors.wait; selectedwafer = tvwwaferlist.selectedvalue.tostring(); populatebluetapelist(); mouse.overridecursor = null; } private void initthread_dowork(object sender, doworkeventargs e) { if (!handled) { populateaoistatelist(); tvwpresenter = new treeviewpresenter(tvwwaferlist, txtfilter, this); tvwpresenter.waferlist = datalibrary.getwaferlist(); handled = true; } } private void initthread_runworkercompleted(object sender, runworkercompletedeventargs e) { tvwpresenter.treeview.datacontext = tvwpresenter.processesandwafers; tvwpresenter.waferlistcache = tvwpresenter.processesandwafers; tvwpresenter.processarray = tvwpresenter.waferlistcache.toarray(); //todo: update status text block } }
answered (2nd comment) dilshod:
the fix change list observablecollection.
once made change, worked expected; dilshod!
Comments
Post a Comment