c# - Invoke command OnSelectionChanged in GridViewComboBoxColumn WPF -
is there way can invoke command
, pass selecteditem
parameter viewmodel
when selection change occurs?
xaml:
<telerik:gridviewcomboboxcolumn itemssource="{binding statuslist, mode=twoway, updatesourcetrigger=propertychanged}" selectedvaluememberpath="statusname" displaymemberpath="statusname" datamemberbinding="{binding shipped, mode=twoway, updatesourcetrigger=propertychanged}" isvisible="{binding isexist, mode=twoway}"> </telerik:gridviewcomboboxcolumn>
i tried adding interation triggers
couldn't able find exact event pass selecteditem
parameter,
<i:interaction.triggers> <i:eventtrigger eventname="contextmenuclosing"> <i:invokecommandaction command="{binding statusdropdowncommand, mode=oneway}"/> </i:eventtrigger> </i:interaction.triggers>
viewmodel:
public icommand statusdropdowncommand { { return new relaycommand(statusdropdown); } } void statusdropdown() { }
kindly help.
updated code:
<telerik:gridviewcomboboxcolumn itemssource="{binding statuslist, mode=twoway, updatesourcetrigger=propertychanged}" selectedvaluememberpath="statusname" displaymemberpath="statusname" datamemberbinding="{binding shipped, mode=twoway, updatesourcetrigger=propertychanged}" isvisible="{binding isexist, mode=twoway}"> <i:interaction.triggers> <converter:routedeventtrigger routedevent="selector.selectionchanged" > <converter:customcommandaction command="{binding selectionchangedcommand}" /> </converter:routedeventtrigger> </i:interaction.triggers> </telerik:gridviewcomboboxcolumn>
issue occured:
seems subscription selector.selectionchanged routed event should job.
<i:interaction.triggers> <local:routedeventtrigger routedevent="selector.selectionchanged"> <local:customcommandaction command="{binding selectionchangedcommand}" /> </local:routedeventtrigger> </i:interaction.triggers>
you need custom trigger handle attached events:
public class routedeventtrigger : eventtriggerbase<dependencyobject> { routedevent _routedevent; public routedevent routedevent { { return _routedevent; } set { _routedevent = value; } } public routedeventtrigger() { } protected override void onattached() { behavior behavior = base.associatedobject behavior; frameworkelement associatedelement = base.associatedobject frameworkelement; if (behavior != null) { associatedelement = ((iattachedobject)behavior).associatedobject frameworkelement; } if (associatedelement == null) { throw new argumentexception("routed event trigger can associated framework elements"); } if (routedevent != null) { associatedelement.addhandler(routedevent, new routedeventhandler(this.onroutedevent)); } } void onroutedevent(object sender, routedeventargs args) { base.onevent(args); } protected override string geteventname() { return routedevent.name; } }
also may use own action triggering command:
public sealed class customcommandaction : triggeraction<dependencyobject> { public static readonly dependencyproperty commandparameterproperty = dependencyproperty.register("commandparameter", typeof(object), typeof(customcommandaction), null); public static readonly dependencyproperty commandproperty = dependencyproperty.register( "command", typeof(icommand), typeof(customcommandaction), null); public icommand command { { return (icommand)this.getvalue(commandproperty); } set { this.setvalue(commandproperty, value); } } public object commandparameter { { return this.getvalue(commandparameterproperty); } set { this.setvalue(commandparameterproperty, value); } } protected override void invoke(object parameter) { if (this.associatedobject != null) { icommand command = this.command; if (command != null) { if (this.commandparameter != null) { if (command.canexecute(this.commandparameter)) { command.execute(this.commandparameter); } } else { if (command.canexecute(parameter)) { command.execute(parameter); } } } } } }
Comments
Post a Comment