private void SetHorizontalSplitPosition(int index, float percentage) { percentage = Math.Min(100, Math.Max(0, percentage)); if (RowCount == 0 || index < 0 || index >= RowCount - 1 || Height <= 0) { return; } var heights = RowStyles.OfType <RowStyle>().Select(x => x.Height).ToList(); var currentPercent = heights.GetRange(0, index + 1).Sum(); if (percentage < currentPercent) { // <-- var diff = currentPercent - percentage; for (var i = index; i >= 0 && diff > 0; i--) { var h = heights[i]; var nh = Math.Max(MinimumViewSize, h - diff); heights[i] = nh; heights[index + 1] += (h - nh); diff -= (h - nh); } } else if (percentage > currentPercent) { // --> var diff = percentage - currentPercent; for (var i = index + 1; i < heights.Count && diff > 0; i++) { var h = heights[i]; var nh = Math.Max(MinimumViewSize, h - diff); heights[i] = nh; heights[index] += (h - nh); diff -= (h - nh); } } for (var i = 0; i < RowCount; i++) { heights[i] = (float)Math.Round(heights[i] * 10) / 10; RowStyles[i].Height = heights[i]; } }