Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

wpf app how to get all elements which are exposed to script

   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
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wpf #app #elements #exposed #script
ADD COMMENT
Topic
Name
4+5 =