我正在尝试按类型和标签名称检索所有元素。我已经找到了一些例子:
我试图修改其中的一些示例,但它们从未给我想要的结果。
所需方法的示例:
public static Collection<T> FindAll<T>(DependencyObject parent, string childName)
where T : DependencyObject
{
//code that gives me the collection
}
Run Code Online (Sandbox Code Playgroud)
示例所需的标记对象:
<Ellipse Tag="tagname" Fill="Blue" Width="25" Height="25" />
<Ellipse Tag="tagname" Fill="Blue" Width="25" Height="25" />
<Ellipse Tag="tagname" Fill="Blue" Width="25" Height="25" />
Run Code Online (Sandbox Code Playgroud)
我试过的方法:
public static Collection<T> FindAll<T>(DependencyObject parent, string childName)
where T : DependencyObject
{
Collection<T> result=null;
Boolean b = true;
int c = 0;
while (b)
{
T obj = FindChild<T>(parent, childName, c,-1);
if (obj == …Run Code Online (Sandbox Code Playgroud)