mvvm - WPF ComboBox SelectionChanged event to command not firing -
i have following xaml of combobox
has code-behind selectionchanged
event handler , command property of viewmodel. have set selectedindex
property 0. when run project, code-behind handler invoked, command
not executed. want command
should executed selectedindex=0
first time view loaded.
<combobox name="listcombobox" selectionchanged="listcombobox_selectionchanged" selectedindex="0" selectedvaluepath="content" margin="5,0" height="35" width="150" verticalalignment="center" horizontalalignment="left"> <i:interaction.triggers> <i:eventtrigger eventname="selectionchanged"> <i:invokecommandaction command="{binding listtypecomboselectionchangedcmd}" commandparameter="{binding elementname=listcombobox, path=selectedvalue}"/> </i:eventtrigger> </i:interaction.triggers> <comboboxitem content="itemone" /> <comboboxitem content="itemtwo" /> <comboboxitem content="itemthree" /> </combobox>
update
code-behind event handler:
private void listcombobox_selectionchanged(object sender, selectionchangedeventargs e) { }
icommand object:
public icommand listtypecomboselectionchangedcmd { { return new relaycommand<string>(listtypecomboselectionchangedcmdexec); } private set; }
icommand handler:
private void listtypecomboselectionchangedcmdexec(string listtype) { }
bind selectedvalue
property
on view model.
in property
set{...}
block logic there or call
listtypecomboselectionchangedcmdexec(value)
Comments
Post a Comment