WPF 遍历资源字典中的控件

object obItem=this.FindResource("canvasdt");
if (obItem is System.Windows.DataTemplate)
{
System.Windows.DataTemplate getDtemplate = obItem as System.Windows.DataTemplate;
if (getDtemplate.LoadContent() is Border)
{
Border b = getDtemplate.LoadContent() as Border;
if (b.Child is Grid)
{
if ((b.Child as Grid).FindName("toolStackPanel") is StackPanel)
{
//((b.Child as Grid).FindName("toolStackPanel") as StackPanel).DataContext = CKInstanceBase<CommandBind>.Instance;
}
}
}
}

上面仅仅举例,如果多级,这递归即可

WPF 遍历资源字典中的控件

上一篇:C#基础知识学习


下一篇:WPF global exception handler