View Code
private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject
{
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<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
View Code
ListBox lbCurrent = e.Source as ListBox;
foreach (object o in lbCurrent.Items)
{
ListBoxItem lbi
= lbCurrent.ItemContainerGenerator.ContainerFromItem(o) as ListBoxItem;
ContentPresenter myContentPresenter
= FindVisualChild<ContentPresenter>(lbi);
DataTemplate myDataTemplate
= myContentPresenter.ContentTemplate;
ToggleButton tbhaha
= myDataTemplate.FindName("tbContainer", myContentPresenter) as ToggleButton;
tbhaha.IsChecked
= false;
}
tb.IsChecked
= true;
posted on 2011-04-08 11:55  暗月随风  阅读(2173)  评论(0编辑  收藏  举报