Search This Blog

Wednesday, May 21, 2014

Get tree visual elements WPF

WPFWindows > MediaVisualTreeHelper 

VisualTreeHelper provides methods that perform

tasks involving nodes in a visual tree.


Example:

Get tree visual elements for user control


FrameworkElement fe = (FrameworkElement)YourControl;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(fe); i++)
{
   Grid childVisual = (Grid)VisualTreeHelper.GetChild(fe, i);
   childVisual.Width = sp.ActualWidth;
}