예제 #1
0
            protected void PropogateToRoot(Nullable <bool> isChecked)
            {
                // If isChecked is not null (some checked), find out what it's value should be
                if (isChecked != null)
                {
                    bool hasChecked   = false;
                    bool hasUnchecked = false;
                    foreach (object item in Items)
                    {
                        FolderTreeViewItem tvm = item as FolderTreeViewItem;
                        if (tvm != null)
                        {
                            if (tvm.IsChecked == null)
                            {
                                hasChecked   = true;
                                hasUnchecked = true;
                                break;
                            }
                            else if (tvm.IsChecked == true)
                            {
                                hasChecked = true;
                                if (hasUnchecked)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                hasUnchecked = true;
                                if (hasChecked)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (hasChecked && hasUnchecked)
                    {
                        isChecked = null;
                    }
                    else if (hasChecked)
                    {
                        isChecked = true;
                    }
                    else
                    {
                        isChecked = false;
                    }
                }

                // If isChecked is different from current value, update it and propogate
                if (fCheckBox.IsChecked != isChecked)
                {
                    fPropogating        = true;
                    fCheckBox.IsChecked = isChecked;
                    FolderTreeViewItem tvm = Parent as FolderTreeViewItem;
                    if (tvm != null)
                    {
                        tvm.PropogateToRoot(isChecked);
                    }
                    fPropogating = false;
                }
            }