how find index of listboxitem if set within datatemplate textbox control? here wpf:
<listbox name="scripteditor" margin="10" height="291" itemssource="{binding path=script}" selectionchanged="scripteditor_selectionchanged_1" > <listbox.itemtemplate> <datatemplate> <textbox text="{binding path=command}"previewmousedoubleclick="command_doubleclick" gotfocus="scripteditor_gotfocus" /> </datatemplate> </listbox.itemtemplate> </listbox>
when gain focus of textbox (text bound observablecollection), cannot use selectionchanged event on listbox. know how can determine index of textbox have gained focus in.
thanks
you bind alternationcount
script.count
add alternationindex
itemscontrol
(listbox) textbox
tag
property can access gotfocus
event handler.
example:
<listbox name="scripteditor" margin="10" height="291" itemssource="{binding script}" alternationcount="{binding script.count}" > <listbox.itemtemplate> <datatemplate> <textbox text="{binding ., mode=oneway}" gotfocus="scripteditor_gotfocus" tag="{binding path=(itemscontrol.alternationindex), mode=oneway, relativesource={relativesource findancestor, ancestortype={x:type listboxitem}}}" /> </datatemplate> </listbox.itemtemplate> </listbox> private void scripteditor_gotfocus(object sender, routedeventargs e) { int index = (int)(sender textbox).tag; }