I\'m trying to retrieve of all elements by type and tag name. I already found some examples:
How can I find WPF controls by name or type?
https://stackoverfl
Tried a lot of solutions recommended by the community. None really worked. Had to modify a bit. Here is what worked for me.
List<LayoutPanel> panels = new List<LayoutPanel>();
foreach (object rawChild in LogicalTreeHelper.GetChildren(dockManager))
{
if (rawChild is DependencyObject)
{
DependencyObject child = (DependencyObject)rawChild;
if (child is LayoutPanel)
{
panels.Add((LayoutPanel)child);
}
foreach (LayoutPanel childOfChild in FindLogicalChildren<LayoutPanel>(child))
{
panels.Add(childOfChild);
}
}
}
var requiredPanel = panels.Where(t => t.Tag.ToString() == tagName).FirstOrDefault();
You could use the following FindVisualChildren
method:
Find all controls in WPF Window by type
...and simply filter the results:
string tagName = "tagname";
IEnumerable<Ellipse> elements = FindVisualChildren<Ellipse>(this).Where(x => x.Tag != null && x.Tag.ToString() == tagName);