private Rectangle ApplyPadding(Rectangle rect, Padding padding)
{
// Ignore an empty padding value
if (!padding.Equals(CommonHelper.InheritPadding))
{
// Get the orientation to use for applying the padding
VisualOrientation orientation = Orientation;
// Do we need to apply right to left?
if (_rightToLeftLayout && (_rightToLeft == RightToLeft.Yes))
{
// Reverse the left and right only
switch (orientation)
{
case VisualOrientation.Left:
orientation = VisualOrientation.Right;
break;
case VisualOrientation.Right:
orientation = VisualOrientation.Left;
break;
}
}
// The orientation determines how the border padding is
// used to reduce the space available for children
switch (orientation)
{
case VisualOrientation.Top:
rect = new Rectangle(rect.X + padding.Left, rect.Y + padding.Top,
rect.Width - padding.Horizontal, rect.Height - padding.Vertical);
break;
case VisualOrientation.Bottom:
rect = new Rectangle(rect.X + padding.Left, rect.Y + padding.Bottom,
rect.Width - padding.Horizontal, rect.Height - padding.Vertical);
break;
case VisualOrientation.Left:
rect = new Rectangle(rect.X + padding.Top, rect.Y + padding.Left,
rect.Width - padding.Vertical, rect.Height - padding.Horizontal);
break;
case VisualOrientation.Right:
rect = new Rectangle(rect.X + padding.Bottom, rect.Y + padding.Left,
rect.Width - padding.Vertical, rect.Height - padding.Horizontal);
break;
default:
// Should never happen!
Debug.Assert(false);
break;
}
}
return rect;
}