i have datagrid, populated programatically data retrieved webservice. last column of datagrid contains checkboxes, allow show each rows value on map. column created template column this:
datagridtemplatecolumn column = new datagridtemplatecolumn(); column.header = "show on map"; datatemplate dt = new datatemplate(); frameworkelementfactory checkboxfactory = new frameworkelementfactory(typeof(checkbox)); checkboxfactory.addhandler(checkbox.clickevent, new routedeventhandler(checkboxclicked), true); dt.visualtree = checkboxfactory; column.celltemplate = dt; datagrid.columns.add(column);
if users clicks on 1 of checkboxes, checkboxclicked
method invoked , displays corresponding row values icon on map (as mentioned). works well. however, user may close window containing datagrid, whereas map stays on screen, displayed icons.
now, when user reopens window datagrid, i'd preselect checkbox, according showing icons. since checkboxes not have binding, i'm unable match icons them. how can done? there way programatically preselect them? or there still way create binding?
finally, i've found solution. hosch250s comment lead me on right track (how can upvote comment?). answer can found here: binding in code.
the easiest way set checkbox state programmatically create binding:
binding binding = new binding("ischecked"); binding.mode = bindingmode.oneway; binding.source = this; checkboxfactory.setbinding(checkbox.ischeckedproperty, binding);
and implement property in current context:
public bool ischecked { { return dowhatevertofindoutifchecked(); } }
Comments
Post a Comment