Esempio n. 1
0
        protected void AddNewControl(UIElement cntl)
        {
            ClVariable clX      = FindClVariableByUIElementAndProperty(cntl, "X");
            ClVariable clY      = FindClVariableByUIElementAndProperty(cntl, "Y");
            ClVariable clWidth  = FindClVariableByUIElementAndProperty(cntl, "Width");
            ClVariable clHeight = FindClVariableByUIElementAndProperty(cntl, "Height");
            ClVariable clLeft   = FindClVariableByUIElementAndProperty(cntl, "Left");
            ClVariable clRight  = FindClVariableByUIElementAndProperty(cntl, "Right");
            ClVariable clCenter = FindClVariableByUIElementAndProperty(cntl, "Center");
            ClVariable clMiddle = FindClVariableByUIElementAndProperty(cntl, "Middle");
            ClVariable clTop    = FindClVariableByUIElementAndProperty(cntl, "Top");
            ClVariable clBottom = FindClVariableByUIElementAndProperty(cntl, "Bottom");

            // X = Left
            solver.AddConstraint(new ClLinearEquation(clX, new ClLinearExpression(clLeft), ClStrength.Required));

            // X = Center - (Width/2)
            solver.AddConstraint(new ClLinearEquation(clX,
                                                      new ClLinearExpression(clCenter).Minus(new ClLinearExpression(clWidth).Divide(2)), ClStrength.Required));

            // X = Right - Width
            solver.AddConstraintNoException(new ClLinearEquation(clX,
                                                                 new ClLinearExpression(clRight).Minus(clWidth), ClStrength.Required));

            // Y = Top
            solver.AddConstraint(new ClLinearEquation(clY, new ClLinearExpression(clTop), ClStrength.Required));

            // Y = Middle - (Height/2)
            solver.AddConstraint(new ClLinearEquation(clY,
                                                      new ClLinearExpression(clMiddle).Minus(new ClLinearExpression(clHeight).Divide(2)), ClStrength.Required));

            // Y = Bottom - Height
            solver.AddConstraint(new ClLinearEquation(clY,
                                                      new ClLinearExpression(clBottom).Minus(clHeight), ClStrength.Required));
        }