コード例 #1
0
        static bool IsStopSearch(DependencyObject obj, bool stopWindowOrUserControl, bool stopControlDriver, int index)
        {
            if (stopWindowOrUserControl && (0 < index))
            {
                if (((obj is UserControl) || (obj is Page) || (obj is Window)))
                {
                    return(true);
                }
                var info = DriverCreatorUtils.GetDriverInfo(obj, DriverCreatorAdapter.TypeFullNameAndUserControlDriver);
                if (info != null)
                {
                    return(true);
                }
            }

            if (stopControlDriver)
            {
                var info = DriverCreatorUtils.GetDriverInfo(obj, DriverCreatorAdapter.TypeFullNameAndControlDriver);
                if (info != null && !info.SearchDescendantUserControls)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        private void GetAllWindowAndUserControl(bool isControlTreeOnly, DependencyObject control, Dictionary <Type, DependencyObject> targets, List <Type> getFromControlTreeOnly, List <DependencyObject> recursiveCheck)
        {
            if (control == null)
            {
                return;
            }

            //ルート以外はすでに割り当てがあれば再生成しないようにする
            var addToTarget = true;

            if (DriverCreatorUtils.GetDriverInfo(control, DriverCreatorAdapter.TypeFullNameAndControlDriver) != null ||
                DriverCreatorUtils.GetDriverInfo(control, DriverCreatorAdapter.TypeFullNameAndWindowDriver) != null ||
                DriverCreatorUtils.GetDriverInfo(control, DriverCreatorAdapter.TypeFullNameAndUserControlDriver) != null)
            {
                addToTarget = false;
            }

            //再帰チェック
            if (CollectionUtility.HasReference(recursiveCheck, control))
            {
                return;
            }
            recursiveCheck.Add(control);

            if ((control is Window) ||
                ((control is UserControl) && (control.GetType() != typeof(UserControl))) ||
                ((control is Page) && (control.GetType() != typeof(Page))))
            {
                if (addToTarget)
                {
                    targets[control.GetType()] = control;
                    if (isControlTreeOnly)
                    {
                        getFromControlTreeOnly.Add(control.GetType());
                    }
                }

                //Form, UserControlの時はメンバも見る
                foreach (var e in GetFields(control))
                {
                    //まれにGridなどををメンバに持っている場合がある。
                    if (e.Control.GetType().Assembly == typeof(Grid).Assembly)
                    {
                        continue;
                    }

                    GetAllWindowAndUserControl(false, e.Control, targets, getFromControlTreeOnly, recursiveCheck);
                }
            }
            if (!(control is FrameworkElement))
            {
                return;
            }

            foreach (var e in WPFUtility.GetLogicalTreeDescendants(control, true, true, 0))
            {
                GetAllWindowAndUserControl(true, e, targets, getFromControlTreeOnly, recursiveCheck);
            }
            foreach (var e in WPFUtility.GetVisualTreeDescendants(control, true, true, 0))
            {
                GetAllWindowAndUserControl(true, e, targets, getFromControlTreeOnly, recursiveCheck);
            }
        }