Did I mention that intellisense and the list of controls to add to a WPF form all do not work for me in visual studio, I suspect because of the bogus error message I get for every form in my project ?
The solution to this is the following code:
ComboBoxItem itm = PDFList.ItemContainerGenerator.ContainerFromItem(i) as ComboBoxItem;
ContentPresenter myContentPresenter = FindVisualChild
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
CheckBox cb = myDataTemplate.FindName("chkSelect", myContentPresenter) as CheckBox;
if (cb != null)
cb.IsChecked = true;
Simple, right ? But you also need to add this method. You need to add a METHOD to give yourself the reusable ability to find a control inside a template in only 5 lines of code. Insane....
Here's that method
private childItem FindVisualChild
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
No comments:
Post a Comment