xaml - WPF Mouse Binding on Listbox Item Template Inconsistent -
i have listbox binds observable collection of custom type displays each item through data template:
<listbox x:name="listbox" style="{staticresource customlistbox}" itemssource="{binding handstats}" height="410" width="150" > <listbox.itemtemplate> <datatemplate> <stackpanel orientation="vertical"> <stackpanel orientation="horizontal"> <textblock text="{binding holecards[0].cardparts.value}" margin="2"/> <image source="{binding holecards[0].suitimagepath}" width="10" height="10" margin="2"/> <textblock text="{binding holecards[1].cardparts.value}" margin="2"/> <image source="{binding holecards[1].suitimagepath}" width="10" height="10" margin="2"/> </stackpanel> <stackpanel orientation="horizontal"> <textblock text="runs:" margin="2"/> <textblock text="{binding numberofruns}" margin="2"/> <textblock text="players:" margin="2"/> <textblock text="{binding numberofplayers}" margin="2"/> </stackpanel> <stackpanel.inputbindings> <mousebinding gesture="leftclick" command="{binding path=datacontext.populatereport, relativesource={relativesource ancestortype={x:type usercontrol}}}" commandparameter="{binding elementname=listbox, path=selecteditem}"/> </stackpanel.inputbindings> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox>
image of listbox: http://imgur.com/a/qgz8z
now ideally when click anywhere in stack panel each item, item selected , command fired. problem item selection , command firing not working should.
the item become selected if click in between text blocks or in empty space right of text blocks, command not fired. command fire once have firstly selected item, , click again onto 1 of text blocks or 1 of images.
i'm still quite new wpf if i'm not making sense please let me know, in advance :)
so instead of using input bindings decided use different method. created property in vm , bound selected item of list. every time select new item (which works now) property updated in vm. simple!
Comments
Post a Comment