private Brush[] _getBrushes(Color C, CornerRadius R) { if (!_gradientBrushes.ContainsKey(C, R)) { var brushes = new Brush[9]; brushes[0] = _getRadialBrush(R.TopLeft, new Point(1, 1)); // top-left corner brushes[1] = _getLinearBrush(new Point(0, 1), new Point(0, 0)); // top edge brushes[2] = _getRadialBrush(R.TopRight, new Point(0, 1)); // top-right corner brushes[3] = _getLinearBrush(new Point(1, 0), new Point(0, 0)); // left edge brushes[4] = new SolidColorBrush(C); // center brushes[5] = _getLinearBrush(new Point(0, 0), new Point(1, 0)); // right edge brushes[6] = _getRadialBrush(R.BottomLeft, new Point(1, 0)); // bottom-left corner brushes[7] = _getLinearBrush(new Point(0, 0), new Point(0, 1)); // bottom edge brushes[8] = _getRadialBrush(R.BottomRight, new Point(0, 0)); // bottom-right corner brushes.Apply(b => b.Freeze()); lock (_lock) { _gradientBrushes[C, R] = brushes; } } return _gradientBrushes[C, R]; }