How do I get find my "CheckBox" item that is in the ItemTemplate?
Firstly, don't if there's any way you can avoid it. It's much cleaner to bind the various properties of the CheckBox
to your view model rather than trying to pull them out manually.
That said, if you need to get to your CheckBox
, you can should be able to use code like this:
var container = _itemsControl.ItemContainerGenerator.ContainerFromItem(dahCurrentItem) as FrameworkElement;
var checkBox = container.FindName("MyCheckBox") as CheckBox;
OK, Kent gets the credit, but it was only mostly right :)
// This part was good:
var container = _itemsControl.ItemContainerGenerator.ContainerFromItem(dahCurrentItem) as FrameworkElement;
but... the second part would return null, so it had to be as follows:
var checkBox = _itemsControl.ItemTemplate.FindName("MyCheckBox", container) as CheckBox;
His code looked like it should have worked, but for my case, I had to do this instead.