private void ExpandRowAsRecursion(OrganizationForSelect organization, SelectStateEnum state)
 {
     organization.SelectState = state;
     if (organization.ChildrenOrganizations != null && organization.ChildrenOrganizations.Count() > 0)
     {
         radTreeListView.ExpandHierarchyItem(organization);
         foreach (OrganizationForSelect item in organization.ChildrenOrganizations)
         {
             //var row = radTreeListView.ItemContainerGenerator.ContainerFromItem(item) as RadTreeViewItem;
             if (radTreeListView.Items.Contains(item))
             {
                 ExpandRowAsRecursion(item, state);
             }
         }
     }
 }
        private void checkCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            CheckBox cb = e.OriginalSource as CheckBox;

            if (cb != null)
            {
                OrganizationForSelect organization = cb.DataContext as OrganizationForSelect;
                var state = cb.IsChecked.Value ? SelectStateEnum.Selected : SelectStateEnum.UnSelected;
                ExpandRowAsRecursion(organization, state);
                var root = _dataContext.GetRootOrganization(organization);
                if (root != null)
                {
                    ResetOrganizationState(root);
                }
                ResetToggleAllState();
            }
        }
        private void Grid_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            Grid cb = sender as Grid;
            OrganizationForSelect organization = cb.DataContext as OrganizationForSelect;

            if (organization.SelectState == SelectStateEnum.UnSelected || organization.SelectState == SelectStateEnum.SelfUnSelected)
            {
                organization.SelectState = SelectStateEnum.SelfSelected;
            }
            else
            {
                organization.SelectState = SelectStateEnum.SelfUnSelected;
            }
            var root = _dataContext.GetRootOrganization(organization);

            if (root != null)
            {
                ResetOrganizationState(root);
            }
            ResetToggleAllState();
        }
 private void ResetOrganizationState(OrganizationForSelect organization)
 {
     if (organization.ChildrenOrganizations != null && organization.ChildrenOrganizations.Count() > 0)
     {
         var children = organization.ChildrenOrganizations.Where(o => radTreeListView.Items.Contains(o)).ToList();
         if (children.Count > 0)
         {
             children.ForEach(o => ResetOrganizationState(o));
             var flag = (organization.SelectState == SelectStateEnum.Selected || organization.SelectState == SelectStateEnum.SelfSelected);//原先是否被选中
             if (children.All(o => o.SelectState == SelectStateEnum.Selected))
             {
                 organization.SelectState = flag ? SelectStateEnum.Selected : SelectStateEnum.SelfUnSelected;
             }
             else if (children.Any(o => o.SelectState != SelectStateEnum.UnSelected))
             {
                 organization.SelectState = flag ? SelectStateEnum.SelfSelected : SelectStateEnum.SelfUnSelected;
             }
             else
             {
                 organization.SelectState = flag ? SelectStateEnum.SelfSelected : SelectStateEnum.UnSelected;
             }
         }
     }
 }