Example #1
0
        /// <summary>Scan all the controls in the sub-VisualTree staring at node "depObj", and disable the appropriate ones
        /// A node should be disabled only if it does not satisfy neither of the following two criteria:
        /// (1) it is not configured to be enabled in popupView
        /// (2) none of its subnode is configured to be enabled in popupView
        /// </summary>
        /// <param name="depObj">A node in the visual tree</param>
        /// <param name="popupView">a PopupView</param>
        /// <returns>false if depObj is disabled, yes otherwise</returns>
        private bool ScanAndDisableControls(DependencyObject depObj, PopupView popupView)
        {
            if (depObj == PopupFrame)
            {
                return(true);
            }
            FrameworkElement control = depObj as FrameworkElement;

            if (control != null)
            {
                if (popupView != null)
                {
                    if (popupView.IsControlToAllowEnabled(control.Name))
                    {
                        return(true);
                    }
                }
            }
            bool hasChildrenToAllowEnabled = false;
            int  depObjCount = VisualTreeHelper.GetChildrenCount(depObj);

            for (int i = 0; i < depObjCount; i++)
            {
                if (ScanAndDisableControls(VisualTreeHelper.GetChild(depObj, i), popupView))
                {
                    hasChildrenToAllowEnabled = true;
                }
            }
            if (!hasChildrenToAllowEnabled)
            {
                if (control != null)
                {
                    if (control is ISupportUserInput)
                    {
                        (control as ISupportUserInput).AllowUserInput = false;
                    }
                    else if (control is Canvas)
                    {
                        control.IsEnabled = false;
                    }
                }
                return(false);
            }
            return(true);
        }