private static DataGridColumnHeader[] GetAllVisibleColumnHeaders(DataGrid dataGrid)
        {
            if (dataGrid == null)
            {
                return(null);
            }

            dataGrid.UpdateLayout();
            DataGridColumnHeader[] columnHeaders = CustomVisualTreeHelper <DataGridColumnHeader> .FindChildrenRecursive(dataGrid);

            return((from DataGridColumnHeader columnHeader in columnHeaders
                    where columnHeader != null && columnHeader.Column != null
                    select columnHeader).ToArray());
        }
Exemplo n.º 2
0
            public static TReturn[] FindChildrenRecursive(DependencyObject parent)
            {
                int childCount            = VisualTreeHelper.GetChildrenCount(parent);
                DependencyObject child    = null;
                List <TReturn>   children = new List <TReturn>();

                for (int childIndex = 0; childIndex < childCount; childIndex++)
                {
                    child = VisualTreeHelper.GetChild(parent, childIndex);
                    if (child is TReturn)
                    {
                        children.Add((TReturn)(object)child);
                    }

                    children.AddRange(CustomVisualTreeHelper <TReturn> .FindChildrenRecursive(child));
                }
                return(children.ToArray());
            }