Finding control within WPF itemscontrol

前端 未结 5 1519
春和景丽
春和景丽 2020-11-27 17:26

Hi i have few a single textbox within the the datatemplate for itemscontrol. When i bind the itemcontrols to a observable collection i get two text boxes. But i need to do s

5条回答
  •  独厮守ぢ
    2020-11-27 17:33

    You may want to try using VisualTreeHelper. The properties on ItemsControl itself will only allow you to get the data its bound to, not the template instances used to visualize the data, while VisualTreeHelper allows you to browse around the visual tree as WPF has rendered it.

    If you iterate through the parent ItemControl's visual children (recursively), you shouldn't have any difficulty locating the text boxes you are seeing on screen.

提交回复
热议问题