.net - ListBox with Button in ItemTemplate should do Select on ButtonClick also -
i have listbox itemtemplate. in itemtemplate have button , textblock.
<window x:class="listboxitemwithtogglebutton.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <listbox itemssource="{binding listitems}"> <listbox.itemtemplate> <datatemplate> <stackpanel orientation="horizontal"> <button width="16" height="16" content="c" padding="0" margin="0,0,5,0"></button> <textblock text="{binding path=name}"></textblock> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> </grid>
if click listboxitem on textblock listitem selected too, if click on button listboxitem not selected.
how can both, buttonclick , listboxitem selected every time click button?
you should not need select listviewitem, can dataobject datacontext of button , don't need data other rows since wanted single selection anyway.
in event-handler: var data = (sender frameworkelement).datacontext mydata;
(on side note, being said, need selection @ all? if not use itemscontrol)
to make listviewitem select if button clicked can use itemcontainerstyle this:
<listview.itemcontainerstyle> <style targettype="{x:type listviewitem}"> <setter property="isselected" value="{binding relativesource={relativesource self}, path=iskeyboardfocuswithin, mode=oneway}" /> </style>
Comments
Post a Comment