C# – How to find a control by name or type in the VisualTree

This function allows you to get a control by name and type in a given parent control VisualTree. Keep in mind that recursively searching a tree downwards could be a lengthy process. Note that if the argument name is undefined, the function returns the first found child element that matches the submitted type T. In … Continue reading “C# – How to find a control by name or type in the VisualTree”

C# – How to find the first parent element of a given child that matches the submitted generic type T

This static class allows you to get the first parent element of a given child element in the VisualTree that matches a submitted generic type. This last method “GetParentObject” is an alternative to WPF’s “VisualTreeHelper.GetParent” method, which also supports content elements. Do note, that for content element, this method falls back to the logical tree … Continue reading “C# – How to find the first parent element of a given child that matches the submitted generic type T”