c# - Manual buttoncommand binding -
c# - Manual buttoncommand binding -
i have custom datagridcolumn
creates controls manually editmode so
public class datagridlookupcolumn : datagridtextcolumn { protected override frameworkelement generateeditingelement(datagridcell cell, object dataitem) { var datagridboundcolumn = cell.column datagridboundcolumn; var dockpanel = new dockpanel { horizontalalignment = horizontalalignment.stretch }; var textbox = new textbox { verticalalignment = verticalalignment.center, horizontalalignment = horizontalalignment.stretch }; var button = new button { horizontalalignment = horizontalalignment.right, verticalalignment = verticalalignment.center }; dockpanel.setdock(button, dock.right); dockpanel.children.add(button); dockpanel.children.add(textbox); textbox.style = cell.findresource("textboxwithoutroundedcorners") style; button.style = cell.findresource("lookupbuttonred") style; if (datagridboundcolumn != null) { var cellcontent = cell.content textblock; var bindingexpression = cellcontent != null ? bindingoperations.getbindingexpression(cellcontent, textblock.textproperty) : null; if (bindingexpression != null) { bindlookupcommand(bindingexpression, button); var newbindning = new binding(bindingexpression.parentbinding.path.path) { updatesourcetrigger = bindingexpression.parentbinding.updatesourcetrigger, mode = bindingexpression.parentbinding.mode }; textbox.setbinding(textbox.textproperty, newbindning); } } homecoming dockpanel; } private void bindlookupcommand(bindingexpression bindingexpression, button target) { icommand lookupcommand; if (commandlist.trygetvalue(bindingexpression.parentbinding.path.path, out lookupcommand)) { var bindning = new commandbinding(lookupcommand); target.commandbindings.add(bindning); target.command = lookupcommand; } } public dictionary<string, icommand> commandlist { get; set; } }
as set commandproperty
of button
cant clicked anymore. there else need binding work?
i have verified right commandobject
.
thanks
c# wpf
Comments
Post a Comment