private void CheckedChanged(object sender)
        {
            ToggleButton     toggleButton = sender as ToggleButton;
            FrameworkElement parent       = VisualTreeHelper.GetParent(toggleButton) as FrameworkElement;

            while (parent != null && !(parent is C1OrgChart))
            {
                parent = VisualTreeHelper.GetParent(parent) as FrameworkElement;
            }
            if (parent != null)
            {
                C1OrgChart orgChart = parent as C1OrgChart;
                if (toggleButton.IsChecked != null)
                {
                    orgChart.IsCollapsed = toggleButton.IsChecked.Value;
                }
            }
        }
 // collapse the chart to a given level
 void ToggleCollapseExpand(C1OrgChart node, int level, int maxLevel)
 {
     //ToggleButton button = null;
     if (level >= maxLevel)
     {
         node.IsCollapsed = true;
         // Get ToggleButton and set its IsCheced property to true.
         SetToggleButtonState(node, true);
     }
     else
     {
         node.IsCollapsed = false;
         SetToggleButtonState(node, false);
         foreach (var subNode in node.ChildNodes)
         {
             ToggleCollapseExpand(subNode, level + 1, maxLevel);
         }
     }
 }