找到孩子的名字? [英] Find the name of a child?
问题描述
大家好,
这是我的第一篇文章,在此先感谢您能帮助我,我认为这是一个非常简单的话题.
This is my first post here, thanks in advance if you can help me with I thought was a very simple topic.
每个按钮都有一个通过xaml< Button.Content>嵌套的图像.当我单击一个按钮时,我想找到该按钮的子项(即图像),并使用该图像名称.我尝试了HelpVisualTree.GetChild方法,但返回了 一个DependencyObject,而DependencyObjects没有Name属性.任何的想法?谢谢
Each of my button has an image nested in it via the xaml <Button.Content>. When I click on a button, I'd like to find the child of that button (which is the image), and use this image Name. I tried the HelpVisualTree.GetChild method, but it returns a DependencyObject, and DependencyObjects don't have the Name property. any idea? Thanks
推荐答案
使用类似的东西,
Use something like this,
for (int i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(targetElement, i);
if (child is Image)
{
Image targetItem =(Image)child;
Image targetItem = (Image)child;
} }
这篇关于找到孩子的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!