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;
}
}
}
}

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

posted @ 2019-07-30 15:30  搬砖的L先生  阅读(432)  评论(0编辑  收藏  举报