Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

wpf app how to get all elements

   public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
        {
            if (depObj == null)
            {
                yield return null;
            }
            else
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    var child = VisualTreeHelper.GetChild(depObj, i);

                    if (child != null && child is T)
                        yield return (T)child;

                    foreach (T childOfChild in FindVisualChildren<T>(child))
                        yield return childOfChild;
                }
            }
        }
//usage:

foreach (var tb in FindVisualChildren<TextBlock>(window))
{
    // do something with tb here
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: wpf mouse over style trigger 
Csharp :: c# run cmd hidden 
Csharp :: raycasting in unity 
Csharp :: binary search c# 
Csharp :: c# select oracle database 
Csharp :: how to use navmeshagent in unity 
Csharp :: c# read lines number 3 from string 
Csharp :: upgrade asp.net core to 5.0 
Csharp :: c# convert double to int 
Csharp :: c# string code ascii 
Csharp :: c# turn negative number into positive 
Csharp :: c# space as string 
Csharp :: c# getting user input 
Csharp :: c# datagridview change selected row color 
Csharp :: generate qr code c# 
Csharp :: how to cap rigidbody velocity 
Csharp :: how use unity interfaces 
Csharp :: get list length c# 
Csharp :: json property c# 
Csharp :: wpf resource dictionary 
Csharp :: make command prompt hidden c# 
Csharp :: remove duplicate characters in a string c# 
Csharp :: how to convert object in string JSON c# 
Csharp :: c# public static string 
Csharp :: if debug c# 
Csharp :: dictionary to list c# 
Csharp :: c# get gridview DataKeyNames 
Csharp :: how to insert into a list c# 
Csharp :: Kill System Process in C# 
Csharp :: combobox selected name c# 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =