Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

Stano Turza 7 tahun lalu
induk
melakukan
814434ccd8
46 mengubah file dengan 911 tambahan dan 635 penghapusan
  1. 1 1
      readme.md
  2. 1 1
      samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
  3. 205 0
      src/Avalonia.Base/Utilities/StringTokenizer.cs
  4. 3 6
      src/Avalonia.Controls/Application.cs
  5. 8 1
      src/Avalonia.Controls/GridLength.cs
  6. 0 2
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  7. 0 1
      src/Avalonia.Controls/Properties/AssemblyInfo.cs
  8. 2 2
      src/Avalonia.Controls/TextBlock.cs
  9. 5 2
      src/Avalonia.Controls/TextBox.cs
  10. 2 1
      src/Avalonia.Controls/Utils/UndoRedoHelper.cs
  11. 1 1
      src/Avalonia.Input/DataFormats.cs
  12. 1 1
      src/Avalonia.Input/DataObject.cs
  13. 1 1
      src/Avalonia.Input/DragDrop.cs
  14. 1 2
      src/Avalonia.Input/DragDropDevice.cs
  15. 1 1
      src/Avalonia.Input/DragDropEffects.cs
  16. 1 1
      src/Avalonia.Input/DragEventArgs.cs
  17. 1 1
      src/Avalonia.Input/IDataObject.cs
  18. 1 1
      src/Avalonia.Input/Platform/IPlatformDragSource.cs
  19. 1 1
      src/Avalonia.Input/Raw/IDragDropDevice.cs
  20. 1 1
      src/Avalonia.Input/Raw/RawDragEvent.cs
  21. 1 1
      src/Avalonia.Input/Raw/RawDragEventType.cs
  22. 9 15
      src/Avalonia.Visuals/Matrix.cs
  23. 9 14
      src/Avalonia.Visuals/Media/Brush.cs
  24. 142 292
      src/Avalonia.Visuals/Media/Brushes.cs
  25. 12 15
      src/Avalonia.Visuals/Media/Color.cs
  26. 143 141
      src/Avalonia.Visuals/Media/Colors.cs
  27. 224 0
      src/Avalonia.Visuals/Media/KnownColors.cs
  28. 6 10
      src/Avalonia.Visuals/Point.cs
  29. 7 13
      src/Avalonia.Visuals/Rect.cs
  30. 11 15
      src/Avalonia.Visuals/RelativePoint.cs
  31. 29 26
      src/Avalonia.Visuals/RelativeRect.cs
  32. 5 10
      src/Avalonia.Visuals/Size.cs
  33. 15 20
      src/Avalonia.Visuals/Thickness.cs
  34. 15 13
      src/Gtk/Avalonia.Gtk3/Interop/Native.cs
  35. 9 0
      src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
  36. 1 2
      src/OSX/Avalonia.MonoMac/DragSource.cs
  37. 1 1
      src/OSX/Avalonia.MonoMac/DraggingInfo.cs
  38. 0 2
      src/OSX/Avalonia.MonoMac/TopLevelImpl.cs
  39. 1 1
      src/Windows/Avalonia.Win32/ClipboardFormats.cs
  40. 2 2
      src/Windows/Avalonia.Win32/DataObject.cs
  41. 1 1
      src/Windows/Avalonia.Win32/DragSource.cs
  42. 2 2
      src/Windows/Avalonia.Win32/OleDataObject.cs
  43. 3 4
      src/Windows/Avalonia.Win32/OleDropTarget.cs
  44. 4 3
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
  45. 14 4
      tests/Avalonia.Visuals.UnitTests/Media/BrushTests.cs
  46. 8 0
      tests/Avalonia.Visuals.UnitTests/RelativeRectTests.cs

+ 1 - 1
readme.md

@@ -35,7 +35,7 @@ https://ci.appveyor.com/project/AvaloniaUI/Avalonia/branch/master/artifacts
 
 ## Documentation
 
-As mentioned above, Avalonia is still in alpha and as such there's not much documentation yet. You can take a look at the [getting started page](http://avaloniaui.net/docs/quickstart/) for an overview of how to get started but probably the best thing to do for now is to already know a little bit about WPF/Silverlight/UWP/XAML and ask questions in our [Gitter room](https://gitter.im/AvaloniaUI/Avalonia).
+As mentioned above, Avalonia is still in beta and as such there's not much documentation yet. You can take a look at the [getting started page](http://avaloniaui.net/docs/quickstart/) for an overview of how to get started but probably the best thing to do for now is to already know a little bit about WPF/Silverlight/UWP/XAML and ask questions in our [Gitter room](https://gitter.im/AvaloniaUI/Avalonia).
 
 There's also a high-level [architecture document](http://avaloniaui.net/architecture/project-structure) that is currently a little bit out of date, and I've also started writing blog posts on Avalonia at http://grokys.github.io/.
 

+ 1 - 1
samples/ControlCatalog/Pages/DragAndDropPage.cs → samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs

@@ -1,5 +1,5 @@
 using Avalonia.Controls;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Markup.Xaml;
 using System;
 using System.Collections.Generic;

+ 205 - 0
src/Avalonia.Base/Utilities/StringTokenizer.cs

@@ -0,0 +1,205 @@
+using System;
+using System.Globalization;
+using static System.Char;
+
+namespace Avalonia.Utilities
+{
+    public struct StringTokenizer : IDisposable
+    {
+        private const char DefaultSeparatorChar = ',';
+
+        private readonly string _s;
+        private readonly int _length;
+        private readonly char _separator;
+        private readonly string _exceptionMessage;
+        private readonly IFormatProvider _formatProvider;
+        private int _index;
+        private int _tokenIndex;
+        private int _tokenLength;
+
+        public StringTokenizer(string s, IFormatProvider formatProvider, string exceptionMessage = null)
+            : this(s, GetSeparatorFromFormatProvider(formatProvider), exceptionMessage)
+        {
+            _formatProvider = formatProvider;
+        }
+
+        public StringTokenizer(string s, char separator = DefaultSeparatorChar, string exceptionMessage = null)
+        {
+            _s = s ?? throw new ArgumentNullException(nameof(s));
+            _length = s?.Length ?? 0;
+            _separator = separator;
+            _exceptionMessage = exceptionMessage;
+            _formatProvider = CultureInfo.InvariantCulture;
+            _index = 0;
+            _tokenIndex = -1;
+            _tokenLength = 0;
+
+            while (_index < _length && IsWhiteSpace(_s, _index))
+            {
+                _index++;
+            }
+        }
+
+        public string CurrentToken => _tokenIndex < 0 ? null : _s.Substring(_tokenIndex, _tokenLength);
+
+        public void Dispose()
+        {
+            if (_index != _length)
+            {
+                throw GetFormatException();
+            }
+        }
+
+        public bool TryReadInt32(out Int32 result, char? separator = null)
+        {
+            var success = TryReadString(out var stringResult, separator);
+            result = success ? int.Parse(stringResult, _formatProvider) : 0;
+            return success;
+        }
+
+        public int ReadInt32(char? separator = null)
+        {
+            if (!TryReadInt32(out var result, separator))
+            {
+                throw GetFormatException();
+            }
+
+            return result;
+        }
+
+        public bool TryReadDouble(out double result, char? separator = null)
+        {
+            var success = TryReadString(out var stringResult, separator);
+            result = success ? double.Parse(stringResult, _formatProvider) : 0;
+            return success;
+        }
+
+        public double ReadDouble(char? separator = null)
+        {
+            if (!TryReadDouble(out var result, separator))
+            {
+                throw GetFormatException();
+            }
+
+            return result;
+        }
+
+        public bool TryReadString(out string result, char? separator = null)
+        {
+            var success = TryReadToken(separator ?? _separator);
+            result = CurrentToken;
+            return success;
+        }
+
+        public string ReadString(char? separator = null)
+        {
+            if (!TryReadString(out var result, separator))
+            {
+                throw GetFormatException();
+            }
+
+            return result;
+        }
+
+        private bool TryReadToken(char separator)
+        {
+            _tokenIndex = -1;
+
+            if (_index >= _length)
+            {
+                return false;
+            }
+
+            var c = _s[_index];
+
+            var index = _index;
+            var length = 0;
+
+            while (_index < _length)
+            {
+                c = _s[_index];
+
+                if (IsWhiteSpace(c) || c == separator)
+                {
+                    break;
+                }
+
+                _index++;
+                length++;
+            }
+
+            SkipToNextToken(separator);
+
+            _tokenIndex = index;
+            _tokenLength = length;
+
+            if (_tokenLength < 1)
+            {
+                throw GetFormatException();
+            }
+
+            return true;
+        }
+
+        private void SkipToNextToken(char separator)
+        {
+            if (_index < _length)
+            {
+                var c = _s[_index];
+
+                if (c != separator && !IsWhiteSpace(c))
+                {
+                    throw GetFormatException();
+                }
+
+                var length = 0;
+
+                while (_index < _length)
+                {
+                    c = _s[_index];
+
+                    if (c == separator)
+                    {
+                        length++;
+                        _index++;
+
+                        if (length > 1)
+                        {
+                            throw GetFormatException();
+                        }
+                    }
+                    else
+                    {
+                        if (!IsWhiteSpace(c))
+                        {
+                            break;
+                        }
+
+                        _index++;
+                    }
+                }
+
+                if (length > 0 && _index >= _length)
+                {
+                    throw GetFormatException();
+                }
+            }
+        }
+
+        private FormatException GetFormatException() =>
+            _exceptionMessage != null ? new FormatException(_exceptionMessage) : new FormatException();
+
+        private static char GetSeparatorFromFormatProvider(IFormatProvider provider)
+        {
+            var c = DefaultSeparatorChar;
+
+            var formatInfo = NumberFormatInfo.GetInstance(provider);
+            if (formatInfo.NumberDecimalSeparator.Length > 0 && c == formatInfo.NumberDecimalSeparator[0])
+            {
+                c = ';';
+            }
+
+            return c;
+        }
+    }
+}

+ 3 - 6
src/Avalonia.Controls/Application.cs

@@ -2,20 +2,17 @@
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
 using System;
+using System.Reactive.Concurrency;
 using System.Threading;
 using Avalonia.Controls;
 using Avalonia.Controls.Templates;
 using Avalonia.Input;
 using Avalonia.Input.Platform;
+using Avalonia.Input.Raw;
 using Avalonia.Layout;
-using Avalonia.Rendering;
+using Avalonia.Platform;
 using Avalonia.Styling;
 using Avalonia.Threading;
-using System.Reactive.Concurrency;
-using Avalonia.Input.DragDrop.Raw;
-using Avalonia.Controls.Platform;
-using Avalonia.Platform;
-using Avalonia.Input.DragDrop;
 
 namespace Avalonia
 {

+ 8 - 1
src/Avalonia.Controls/GridLength.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -210,7 +211,13 @@ namespace Avalonia.Controls
         /// <returns>The <see cref="GridLength"/>.</returns>
         public static IEnumerable<GridLength> ParseLengths(string s, CultureInfo culture)
         {
-            return s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Parse(x, culture));
+            using (var tokenizer = new StringTokenizer(s, culture))
+            {
+                while (tokenizer.TryReadString(out var item))
+                {
+                    yield return Parse(item, culture);
+                }
+            }
         }
     }
 }

+ 0 - 2
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@@ -5,8 +5,6 @@ using System.Reactive.Subjects;
 using System.Threading.Tasks;
 using Avalonia.Controls;
 using Avalonia.Input;
-using Avalonia.Input.DragDrop;
-using Avalonia.Input.DragDrop.Raw;
 using Avalonia.Input.Platform;
 using Avalonia.Input.Raw;
 using Avalonia.Threading;

+ 0 - 1
src/Avalonia.Controls/Properties/AssemblyInfo.cs

@@ -11,7 +11,6 @@ using Avalonia.Metadata;
 
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia")]
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls")]
-[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.DragDrop")]
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Embedding")]
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Presenters")]
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Primitives")]

+ 2 - 2
src/Avalonia.Controls/TextBlock.cs

@@ -120,6 +120,7 @@ namespace Avalonia.Controls
                 .Subscribe(_ =>
                 {
                     InvalidateFormattedText();
+                    InvalidateMeasure();
                 });
         }
 
@@ -370,8 +371,6 @@ namespace Avalonia.Controls
                 _constraint = _formattedText.Constraint;
                 _formattedText = null;
             }
-
-            InvalidateMeasure();
         }
 
         /// <summary>
@@ -402,6 +401,7 @@ namespace Avalonia.Controls
         {
             base.OnAttachedToLogicalTree(e);
             InvalidateFormattedText();
+            InvalidateMeasure();
         }
     }
 }

+ 5 - 2
src/Avalonia.Controls/TextBox.cs

@@ -275,8 +275,11 @@ namespace Avalonia.Controls
 
         protected override void OnTextInput(TextInputEventArgs e)
         {
-            HandleTextInput(e.Text);
-            e.Handled = true;
+            if (!e.Handled)
+            {
+                HandleTextInput(e.Text);
+                e.Handled = true;
+            }
         }
 
         private void HandleTextInput(string input)

+ 2 - 1
src/Avalonia.Controls/Utils/UndoRedoHelper.cs

@@ -59,7 +59,7 @@ namespace Avalonia.Controls.Utils
 
         public void UpdateLastState()
         {
-            _states.Last.Value = _host.UndoRedoState;
+            UpdateLastState(_host.UndoRedoState);
         }
 
         public void DiscardRedo()
@@ -94,6 +94,7 @@ namespace Avalonia.Controls.Utils
         public void Clear()
         {
             _states.Clear();
+            _currentNode = null;
         }
 
         bool WeakTimer.IWeakTimerSubscriber.Tick()

+ 1 - 1
src/Avalonia.Input/DragDrop/DataFormats.cs → src/Avalonia.Input/DataFormats.cs

@@ -1,4 +1,4 @@
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     public static class DataFormats
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/DataObject.cs → src/Avalonia.Input/DataObject.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     public class DataObject : IDataObject
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/DragDrop.cs → src/Avalonia.Input/DragDrop.cs

@@ -2,7 +2,7 @@
 using Avalonia.Interactivity;
 using Avalonia.Input.Platform;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     public static class DragDrop
     {

+ 1 - 2
src/Avalonia.Input/DragDrop/DragDropDevice.cs → src/Avalonia.Input/DragDropDevice.cs

@@ -1,10 +1,9 @@
 using Avalonia.Interactivity;
 using Avalonia.VisualTree;
 using System.Linq;
-using Avalonia.Input.DragDrop.Raw;
 using Avalonia.Input.Raw;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     public class DragDropDevice : IDragDropDevice
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/DragDropEffects.cs → src/Avalonia.Input/DragDropEffects.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     [Flags]
     public enum DragDropEffects

+ 1 - 1
src/Avalonia.Input/DragDrop/DragEventArgs.cs → src/Avalonia.Input/DragEventArgs.cs

@@ -1,6 +1,6 @@
 using Avalonia.Interactivity;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     public class DragEventArgs : RoutedEventArgs
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/IDataObject.cs → src/Avalonia.Input/IDataObject.cs

@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 
-namespace Avalonia.Input.DragDrop
+namespace Avalonia.Input
 {
     /// <summary>
     /// Interface to access information about the data of a drag-and-drop operation.

+ 1 - 1
src/Avalonia.Input/Platform/IPlatformDragSource.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Interactivity;
 
 namespace Avalonia.Input.Platform

+ 1 - 1
src/Avalonia.Input/DragDrop/Raw/IDragDropDevice.cs → src/Avalonia.Input/Raw/IDragDropDevice.cs

@@ -1,6 +1,6 @@
 using Avalonia.Input;
 
-namespace Avalonia.Input.DragDrop.Raw
+namespace Avalonia.Input.Raw
 {
     public interface IDragDropDevice : IInputDevice
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/Raw/RawDragEvent.cs → src/Avalonia.Input/Raw/RawDragEvent.cs

@@ -2,7 +2,7 @@
 using Avalonia.Input;
 using Avalonia.Input.Raw;
 
-namespace Avalonia.Input.DragDrop.Raw
+namespace Avalonia.Input.Raw
 {
     public class RawDragEvent : RawInputEventArgs
     {

+ 1 - 1
src/Avalonia.Input/DragDrop/Raw/RawDragEventType.cs → src/Avalonia.Input/Raw/RawDragEventType.cs

@@ -1,4 +1,4 @@
-namespace Avalonia.Input.DragDrop.Raw
+namespace Avalonia.Input.Raw
 {
     public enum RawDragEventType
     {

+ 9 - 15
src/Avalonia.Visuals/Matrix.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -317,23 +318,16 @@ namespace Avalonia
         /// <returns>The <see cref="Matrix"/>.</returns>
         public static Matrix Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToArray();
-
-            if (parts.Length == 6)
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Matrix"))
             {
                 return new Matrix(
-                    double.Parse(parts[0], culture), 
-                    double.Parse(parts[1], culture), 
-                    double.Parse(parts[2], culture), 
-                    double.Parse(parts[3], culture), 
-                    double.Parse(parts[4], culture), 
-                    double.Parse(parts[5], culture));
-            }
-            else
-            {
-                throw new FormatException("Invalid Matrix.");
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble()
+                );
             }
         }
     }

+ 9 - 14
src/Avalonia.Visuals/Media/Brush.cs

@@ -34,26 +34,21 @@ namespace Avalonia.Media
         /// <returns>The <see cref="Color"/>.</returns>
         public static IBrush Parse(string s)
         {
+            Contract.Requires<ArgumentNullException>(s != null);
+            Contract.Requires<FormatException>(s.Length > 0);
+
             if (s[0] == '#')
             {
                 return new SolidColorBrush(Color.Parse(s));
             }
-            else
-            {
-                var upper = s.ToUpperInvariant();
-                var member = typeof(Brushes).GetTypeInfo().DeclaredProperties
-                    .FirstOrDefault(x => x.Name.ToUpperInvariant() == upper);
 
-                if (member != null)
-                {
-                    var brush = (ISolidColorBrush)member.GetValue(null);
-                    return new SolidColorBrush(brush.Color, brush.Opacity);
-                }
-                else
-                {
-                    throw new FormatException($"Invalid brush string: '{s}'.");
-                }
+            var brush = KnownColors.GetKnownBrush(s);
+            if (brush != null)
+            {
+                return brush;
             }
+
+            throw new FormatException($"Invalid brush string: '{s}'.");
         }
     }
 }

+ 142 - 292
src/Avalonia.Visuals/Media/Brushes.cs

@@ -1,8 +1,6 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
-using Avalonia.Media.Immutable;
-
 namespace Avalonia.Media
 {
     /// <summary>
@@ -10,857 +8,709 @@ namespace Avalonia.Media
     /// </summary>
     public static class Brushes
     {
-        /// <summary>
-        /// Initializes static members of the <see cref="Brushes"/> class.
-        /// </summary>
-        static Brushes()
-        {
-            AliceBlue = new ImmutableSolidColorBrush(Colors.AliceBlue);
-            AntiqueWhite = new ImmutableSolidColorBrush(Colors.AntiqueWhite);
-            Aqua = new ImmutableSolidColorBrush(Colors.Aqua);
-            Aquamarine = new ImmutableSolidColorBrush(Colors.Aquamarine);
-            Azure = new ImmutableSolidColorBrush(Colors.Azure);
-            Beige = new ImmutableSolidColorBrush(Colors.Beige);
-            Bisque = new ImmutableSolidColorBrush(Colors.Bisque);
-            Black = new ImmutableSolidColorBrush(Colors.Black);
-            BlanchedAlmond = new ImmutableSolidColorBrush(Colors.BlanchedAlmond);
-            Blue = new ImmutableSolidColorBrush(Colors.Blue);
-            BlueViolet = new ImmutableSolidColorBrush(Colors.BlueViolet);
-            Brown = new ImmutableSolidColorBrush(Colors.Brown);
-            BurlyWood = new ImmutableSolidColorBrush(Colors.BurlyWood);
-            CadetBlue = new ImmutableSolidColorBrush(Colors.CadetBlue);
-            Chartreuse = new ImmutableSolidColorBrush(Colors.Chartreuse);
-            Chocolate = new ImmutableSolidColorBrush(Colors.Chocolate);
-            Coral = new ImmutableSolidColorBrush(Colors.Coral);
-            CornflowerBlue = new ImmutableSolidColorBrush(Colors.CornflowerBlue);
-            Cornsilk = new ImmutableSolidColorBrush(Colors.Cornsilk);
-            Crimson = new ImmutableSolidColorBrush(Colors.Crimson);
-            Cyan = new ImmutableSolidColorBrush(Colors.Cyan);
-            DarkBlue = new ImmutableSolidColorBrush(Colors.DarkBlue);
-            DarkCyan = new ImmutableSolidColorBrush(Colors.DarkCyan);
-            DarkGoldenrod = new ImmutableSolidColorBrush(Colors.DarkGoldenrod);
-            DarkGray = new ImmutableSolidColorBrush(Colors.DarkGray);
-            DarkGreen = new ImmutableSolidColorBrush(Colors.DarkGreen);
-            DarkKhaki = new ImmutableSolidColorBrush(Colors.DarkKhaki);
-            DarkMagenta = new ImmutableSolidColorBrush(Colors.DarkMagenta);
-            DarkOliveGreen = new ImmutableSolidColorBrush(Colors.DarkOliveGreen);
-            DarkOrange = new ImmutableSolidColorBrush(Colors.DarkOrange);
-            DarkOrchid = new ImmutableSolidColorBrush(Colors.DarkOrchid);
-            DarkRed = new ImmutableSolidColorBrush(Colors.DarkRed);
-            DarkSalmon = new ImmutableSolidColorBrush(Colors.DarkSalmon);
-            DarkSeaGreen = new ImmutableSolidColorBrush(Colors.DarkSeaGreen);
-            DarkSlateBlue = new ImmutableSolidColorBrush(Colors.DarkSlateBlue);
-            DarkSlateGray = new ImmutableSolidColorBrush(Colors.DarkSlateGray);
-            DarkTurquoise = new ImmutableSolidColorBrush(Colors.DarkTurquoise);
-            DarkViolet = new ImmutableSolidColorBrush(Colors.DarkViolet);
-            DeepPink = new ImmutableSolidColorBrush(Colors.DeepPink);
-            DeepSkyBlue = new ImmutableSolidColorBrush(Colors.DeepSkyBlue);
-            DimGray = new ImmutableSolidColorBrush(Colors.DimGray);
-            DodgerBlue = new ImmutableSolidColorBrush(Colors.DodgerBlue);
-            Firebrick = new ImmutableSolidColorBrush(Colors.Firebrick);
-            FloralWhite = new ImmutableSolidColorBrush(Colors.FloralWhite);
-            ForestGreen = new ImmutableSolidColorBrush(Colors.ForestGreen);
-            Fuchsia = new ImmutableSolidColorBrush(Colors.Fuchsia);
-            Gainsboro = new ImmutableSolidColorBrush(Colors.Gainsboro);
-            GhostWhite = new ImmutableSolidColorBrush(Colors.GhostWhite);
-            Gold = new ImmutableSolidColorBrush(Colors.Gold);
-            Goldenrod = new ImmutableSolidColorBrush(Colors.Goldenrod);
-            Gray = new ImmutableSolidColorBrush(Colors.Gray);
-            Green = new ImmutableSolidColorBrush(Colors.Green);
-            GreenYellow = new ImmutableSolidColorBrush(Colors.GreenYellow);
-            Honeydew = new ImmutableSolidColorBrush(Colors.Honeydew);
-            HotPink = new ImmutableSolidColorBrush(Colors.HotPink);
-            IndianRed = new ImmutableSolidColorBrush(Colors.IndianRed);
-            Indigo = new ImmutableSolidColorBrush(Colors.Indigo);
-            Ivory = new ImmutableSolidColorBrush(Colors.Ivory);
-            Khaki = new ImmutableSolidColorBrush(Colors.Khaki);
-            Lavender = new ImmutableSolidColorBrush(Colors.Lavender);
-            LavenderBlush = new ImmutableSolidColorBrush(Colors.LavenderBlush);
-            LawnGreen = new ImmutableSolidColorBrush(Colors.LawnGreen);
-            LemonChiffon = new ImmutableSolidColorBrush(Colors.LemonChiffon);
-            LightBlue = new ImmutableSolidColorBrush(Colors.LightBlue);
-            LightCoral = new ImmutableSolidColorBrush(Colors.LightCoral);
-            LightCyan = new ImmutableSolidColorBrush(Colors.LightCyan);
-            LightGoldenrodYellow = new ImmutableSolidColorBrush(Colors.LightGoldenrodYellow);
-            LightGray = new ImmutableSolidColorBrush(Colors.LightGray);
-            LightGreen = new ImmutableSolidColorBrush(Colors.LightGreen);
-            LightPink = new ImmutableSolidColorBrush(Colors.LightPink);
-            LightSalmon = new ImmutableSolidColorBrush(Colors.LightSalmon);
-            LightSeaGreen = new ImmutableSolidColorBrush(Colors.LightSeaGreen);
-            LightSkyBlue = new ImmutableSolidColorBrush(Colors.LightSkyBlue);
-            LightSlateGray = new ImmutableSolidColorBrush(Colors.LightSlateGray);
-            LightSteelBlue = new ImmutableSolidColorBrush(Colors.LightSteelBlue);
-            LightYellow = new ImmutableSolidColorBrush(Colors.LightYellow);
-            Lime = new ImmutableSolidColorBrush(Colors.Lime);
-            LimeGreen = new ImmutableSolidColorBrush(Colors.LimeGreen);
-            Linen = new ImmutableSolidColorBrush(Colors.Linen);
-            Magenta = new ImmutableSolidColorBrush(Colors.Magenta);
-            Maroon = new ImmutableSolidColorBrush(Colors.Maroon);
-            MediumAquamarine = new ImmutableSolidColorBrush(Colors.MediumAquamarine);
-            MediumBlue = new ImmutableSolidColorBrush(Colors.MediumBlue);
-            MediumOrchid = new ImmutableSolidColorBrush(Colors.MediumOrchid);
-            MediumPurple = new ImmutableSolidColorBrush(Colors.MediumPurple);
-            MediumSeaGreen = new ImmutableSolidColorBrush(Colors.MediumSeaGreen);
-            MediumSlateBlue = new ImmutableSolidColorBrush(Colors.MediumSlateBlue);
-            MediumSpringGreen = new ImmutableSolidColorBrush(Colors.MediumSpringGreen);
-            MediumTurquoise = new ImmutableSolidColorBrush(Colors.MediumTurquoise);
-            MediumVioletRed = new ImmutableSolidColorBrush(Colors.MediumVioletRed);
-            MidnightBlue = new ImmutableSolidColorBrush(Colors.MidnightBlue);
-            MintCream = new ImmutableSolidColorBrush(Colors.MintCream);
-            MistyRose = new ImmutableSolidColorBrush(Colors.MistyRose);
-            Moccasin = new ImmutableSolidColorBrush(Colors.Moccasin);
-            NavajoWhite = new ImmutableSolidColorBrush(Colors.NavajoWhite);
-            Navy = new ImmutableSolidColorBrush(Colors.Navy);
-            OldLace = new ImmutableSolidColorBrush(Colors.OldLace);
-            Olive = new ImmutableSolidColorBrush(Colors.Olive);
-            OliveDrab = new ImmutableSolidColorBrush(Colors.OliveDrab);
-            Orange = new ImmutableSolidColorBrush(Colors.Orange);
-            OrangeRed = new ImmutableSolidColorBrush(Colors.OrangeRed);
-            Orchid = new ImmutableSolidColorBrush(Colors.Orchid);
-            PaleGoldenrod = new ImmutableSolidColorBrush(Colors.PaleGoldenrod);
-            PaleGreen = new ImmutableSolidColorBrush(Colors.PaleGreen);
-            PaleTurquoise = new ImmutableSolidColorBrush(Colors.PaleTurquoise);
-            PaleVioletRed = new ImmutableSolidColorBrush(Colors.PaleVioletRed);
-            PapayaWhip = new ImmutableSolidColorBrush(Colors.PapayaWhip);
-            PeachPuff = new ImmutableSolidColorBrush(Colors.PeachPuff);
-            Peru = new ImmutableSolidColorBrush(Colors.Peru);
-            Pink = new ImmutableSolidColorBrush(Colors.Pink);
-            Plum = new ImmutableSolidColorBrush(Colors.Plum);
-            PowderBlue = new ImmutableSolidColorBrush(Colors.PowderBlue);
-            Purple = new ImmutableSolidColorBrush(Colors.Purple);
-            Red = new ImmutableSolidColorBrush(Colors.Red);
-            RosyBrown = new ImmutableSolidColorBrush(Colors.RosyBrown);
-            RoyalBlue = new ImmutableSolidColorBrush(Colors.RoyalBlue);
-            SaddleBrown = new ImmutableSolidColorBrush(Colors.SaddleBrown);
-            Salmon = new ImmutableSolidColorBrush(Colors.Salmon);
-            SandyBrown = new ImmutableSolidColorBrush(Colors.SandyBrown);
-            SeaGreen = new ImmutableSolidColorBrush(Colors.SeaGreen);
-            SeaShell = new ImmutableSolidColorBrush(Colors.SeaShell);
-            Sienna = new ImmutableSolidColorBrush(Colors.Sienna);
-            Silver = new ImmutableSolidColorBrush(Colors.Silver);
-            SkyBlue = new ImmutableSolidColorBrush(Colors.SkyBlue);
-            SlateBlue = new ImmutableSolidColorBrush(Colors.SlateBlue);
-            SlateGray = new ImmutableSolidColorBrush(Colors.SlateGray);
-            Snow = new ImmutableSolidColorBrush(Colors.Snow);
-            SpringGreen = new ImmutableSolidColorBrush(Colors.SpringGreen);
-            SteelBlue = new ImmutableSolidColorBrush(Colors.SteelBlue);
-            Tan = new ImmutableSolidColorBrush(Colors.Tan);
-            Teal = new ImmutableSolidColorBrush(Colors.Teal);
-            Thistle = new ImmutableSolidColorBrush(Colors.Thistle);
-            Tomato = new ImmutableSolidColorBrush(Colors.Tomato);
-            Transparent = new ImmutableSolidColorBrush(Colors.Transparent);
-            Turquoise = new ImmutableSolidColorBrush(Colors.Turquoise);
-            Violet = new ImmutableSolidColorBrush(Colors.Violet);
-            Wheat = new ImmutableSolidColorBrush(Colors.Wheat);
-            White = new ImmutableSolidColorBrush(Colors.White);
-            WhiteSmoke = new ImmutableSolidColorBrush(Colors.WhiteSmoke);
-            Yellow = new ImmutableSolidColorBrush(Colors.Yellow);
-            YellowGreen = new ImmutableSolidColorBrush(Colors.YellowGreen);
-        }
-
         /// <summary>
         /// Gets an <see cref="Colors.AliceBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush AliceBlue { get; private set; }
+        public static ISolidColorBrush AliceBlue => KnownColor.AliceBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.AntiqueWhite"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush AntiqueWhite { get; private set; }
+        public static ISolidColorBrush AntiqueWhite => KnownColor.AntiqueWhite.ToBrush();
 
         /// <summary>
-        /// Gets an <see cref="Colors.AliceBlue"/> colored brush.
+        /// Gets an <see cref="Colors.Aqua"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Aqua { get; private set; }
+        public static ISolidColorBrush Aqua => KnownColor.Aqua.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Aquamarine"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Aquamarine { get; private set; }
+        public static ISolidColorBrush Aquamarine => KnownColor.Aquamarine.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Azure"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Azure { get; private set; }
+        public static ISolidColorBrush Azure => KnownColor.Azure.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Beige"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Beige { get; private set; }
+        public static ISolidColorBrush Beige => KnownColor.Beige.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Bisque"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Bisque { get; private set; }
+        public static ISolidColorBrush Bisque => KnownColor.Bisque.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Black"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Black { get; private set; }
+        public static ISolidColorBrush Black => KnownColor.Black.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.BlanchedAlmond"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush BlanchedAlmond { get; private set; }
+        public static ISolidColorBrush BlanchedAlmond => KnownColor.BlanchedAlmond.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Blue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Blue { get; private set; }
+        public static ISolidColorBrush Blue => KnownColor.Blue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.BlueViolet"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush BlueViolet { get; private set; }
+        public static ISolidColorBrush BlueViolet => KnownColor.BlueViolet.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Brown"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Brown { get; private set; }
+        public static ISolidColorBrush Brown => KnownColor.Brown.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.BurlyWood"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush BurlyWood { get; private set; }
+        public static ISolidColorBrush BurlyWood => KnownColor.BurlyWood.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.CadetBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush CadetBlue { get; private set; }
+        public static ISolidColorBrush CadetBlue => KnownColor.CadetBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Chartreuse"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Chartreuse { get; private set; }
+        public static ISolidColorBrush Chartreuse => KnownColor.Chartreuse.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Chocolate"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Chocolate { get; private set; }
+        public static ISolidColorBrush Chocolate => KnownColor.Chocolate.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Coral"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Coral { get; private set; }
+        public static ISolidColorBrush Coral => KnownColor.Coral.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.CornflowerBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush CornflowerBlue { get; private set; }
+        public static ISolidColorBrush CornflowerBlue => KnownColor.CornflowerBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Cornsilk"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Cornsilk { get; private set; }
+        public static ISolidColorBrush Cornsilk => KnownColor.Cornsilk.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Crimson"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Crimson { get; private set; }
+        public static ISolidColorBrush Crimson => KnownColor.Crimson.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Cyan"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Cyan { get; private set; }
+        public static ISolidColorBrush Cyan => KnownColor.Cyan.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkBlue { get; private set; }
+        public static ISolidColorBrush DarkBlue => KnownColor.DarkBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkCyan"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkCyan { get; private set; }
+        public static ISolidColorBrush DarkCyan => KnownColor.DarkCyan.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkGoldenrod"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkGoldenrod { get; private set; }
+        public static ISolidColorBrush DarkGoldenrod => KnownColor.DarkGoldenrod.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkGray { get; private set; }
+        public static ISolidColorBrush DarkGray => KnownColor.DarkGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkGreen { get; private set; }
+        public static ISolidColorBrush DarkGreen => KnownColor.DarkGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkKhaki"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkKhaki { get; private set; }
+        public static ISolidColorBrush DarkKhaki => KnownColor.DarkKhaki.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkMagenta"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkMagenta { get; private set; }
+        public static ISolidColorBrush DarkMagenta => KnownColor.DarkMagenta.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkOliveGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkOliveGreen { get; private set; }
+        public static ISolidColorBrush DarkOliveGreen => KnownColor.DarkOliveGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkOrange"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkOrange { get; private set; }
+        public static ISolidColorBrush DarkOrange => KnownColor.DarkOrange.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkOrchid"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkOrchid { get; private set; }
+        public static ISolidColorBrush DarkOrchid => KnownColor.DarkOrchid.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkRed"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkRed { get; private set; }
+        public static ISolidColorBrush DarkRed => KnownColor.DarkRed.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkSalmon"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkSalmon { get; private set; }
+        public static ISolidColorBrush DarkSalmon => KnownColor.DarkSalmon.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkSeaGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkSeaGreen { get; private set; }
+        public static ISolidColorBrush DarkSeaGreen => KnownColor.DarkSeaGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkSlateBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkSlateBlue { get; private set; }
+        public static ISolidColorBrush DarkSlateBlue => KnownColor.DarkSlateBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkSlateGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkSlateGray { get; private set; }
+        public static ISolidColorBrush DarkSlateGray => KnownColor.DarkSlateGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkTurquoise"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkTurquoise { get; private set; }
+        public static ISolidColorBrush DarkTurquoise => KnownColor.DarkTurquoise.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DarkViolet"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DarkViolet { get; private set; }
+        public static ISolidColorBrush DarkViolet => KnownColor.DarkViolet.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DeepPink"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DeepPink { get; private set; }
+        public static ISolidColorBrush DeepPink => KnownColor.DeepPink.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DeepSkyBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DeepSkyBlue { get; private set; }
+        public static ISolidColorBrush DeepSkyBlue => KnownColor.DeepSkyBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DimGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DimGray { get; private set; }
+        public static ISolidColorBrush DimGray => KnownColor.DimGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.DodgerBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush DodgerBlue { get; private set; }
+        public static ISolidColorBrush DodgerBlue => KnownColor.DodgerBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Firebrick"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Firebrick { get; private set; }
+        public static ISolidColorBrush Firebrick => KnownColor.Firebrick.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.FloralWhite"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush FloralWhite { get; private set; }
+        public static ISolidColorBrush FloralWhite => KnownColor.FloralWhite.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.ForestGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush ForestGreen { get; private set; }
+        public static ISolidColorBrush ForestGreen => KnownColor.ForestGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Fuchsia"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Fuchsia { get; private set; }
+        public static ISolidColorBrush Fuchsia => KnownColor.Fuchsia.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Gainsboro"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Gainsboro { get; private set; }
+        public static ISolidColorBrush Gainsboro => KnownColor.Gainsboro.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.GhostWhite"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush GhostWhite { get; private set; }
+        public static ISolidColorBrush GhostWhite => KnownColor.GhostWhite.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Gold"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Gold { get; private set; }
+        public static ISolidColorBrush Gold => KnownColor.Gold.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Goldenrod"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Goldenrod { get; private set; }
+        public static ISolidColorBrush Goldenrod => KnownColor.Goldenrod.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Gray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Gray { get; private set; }
+        public static ISolidColorBrush Gray => KnownColor.Gray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Green"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Green { get; private set; }
+        public static ISolidColorBrush Green => KnownColor.Green.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.GreenYellow"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush GreenYellow { get; private set; }
+        public static ISolidColorBrush GreenYellow => KnownColor.GreenYellow.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Honeydew"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Honeydew { get; private set; }
+        public static ISolidColorBrush Honeydew => KnownColor.Honeydew.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.HotPink"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush HotPink { get; private set; }
+        public static ISolidColorBrush HotPink => KnownColor.HotPink.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.IndianRed"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush IndianRed { get; private set; }
+        public static ISolidColorBrush IndianRed => KnownColor.IndianRed.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Indigo"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Indigo { get; private set; }
+        public static ISolidColorBrush Indigo => KnownColor.Indigo.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Ivory"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Ivory { get; private set; }
+        public static ISolidColorBrush Ivory => KnownColor.Ivory.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Khaki"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Khaki { get; private set; }
+        public static ISolidColorBrush Khaki => KnownColor.Khaki.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Lavender"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Lavender { get; private set; }
+        public static ISolidColorBrush Lavender => KnownColor.Lavender.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LavenderBlush"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LavenderBlush { get; private set; }
+        public static ISolidColorBrush LavenderBlush => KnownColor.LavenderBlush.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LawnGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LawnGreen { get; private set; }
+        public static ISolidColorBrush LawnGreen => KnownColor.LawnGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LemonChiffon"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LemonChiffon { get; private set; }
+        public static ISolidColorBrush LemonChiffon => KnownColor.LemonChiffon.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightBlue { get; private set; }
+        public static ISolidColorBrush LightBlue => KnownColor.LightBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightCoral"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightCoral { get; private set; }
+        public static ISolidColorBrush LightCoral => KnownColor.LightCoral.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightCyan"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightCyan { get; private set; }
+        public static ISolidColorBrush LightCyan => KnownColor.LightCyan.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightGoldenrodYellow"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightGoldenrodYellow { get; private set; }
+        public static ISolidColorBrush LightGoldenrodYellow => KnownColor.LightGoldenrodYellow.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightGray { get; private set; }
+        public static ISolidColorBrush LightGray => KnownColor.LightGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightGreen { get; private set; }
+        public static ISolidColorBrush LightGreen => KnownColor.LightGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightPink"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightPink { get; private set; }
+        public static ISolidColorBrush LightPink => KnownColor.LightPink.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightSalmon"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightSalmon { get; private set; }
+        public static ISolidColorBrush LightSalmon => KnownColor.LightSalmon.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightSeaGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightSeaGreen { get; private set; }
+        public static ISolidColorBrush LightSeaGreen => KnownColor.LightSeaGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightSkyBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightSkyBlue { get; private set; }
+        public static ISolidColorBrush LightSkyBlue => KnownColor.LightSkyBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightSlateGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightSlateGray { get; private set; }
+        public static ISolidColorBrush LightSlateGray => KnownColor.LightSlateGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightSteelBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightSteelBlue { get; private set; }
+        public static ISolidColorBrush LightSteelBlue => KnownColor.LightSteelBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LightYellow"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LightYellow { get; private set; }
+        public static ISolidColorBrush LightYellow => KnownColor.LightYellow.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Lime"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Lime { get; private set; }
+        public static ISolidColorBrush Lime => KnownColor.Lime.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.LimeGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush LimeGreen { get; private set; }
+        public static ISolidColorBrush LimeGreen => KnownColor.LimeGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Linen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Linen { get; private set; }
+        public static ISolidColorBrush Linen => KnownColor.Linen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Magenta"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Magenta { get; private set; }
+        public static ISolidColorBrush Magenta => KnownColor.Magenta.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Maroon"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Maroon { get; private set; }
+        public static ISolidColorBrush Maroon => KnownColor.Maroon.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumAquamarine"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumAquamarine { get; private set; }
+        public static ISolidColorBrush MediumAquamarine => KnownColor.MediumAquamarine.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumBlue { get; private set; }
+        public static ISolidColorBrush MediumBlue => KnownColor.MediumBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumOrchid"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumOrchid { get; private set; }
+        public static ISolidColorBrush MediumOrchid => KnownColor.MediumOrchid.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumPurple"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumPurple { get; private set; }
+        public static ISolidColorBrush MediumPurple => KnownColor.MediumPurple.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumSeaGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumSeaGreen { get; private set; }
+        public static ISolidColorBrush MediumSeaGreen => KnownColor.MediumSeaGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumSlateBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumSlateBlue { get; private set; }
+        public static ISolidColorBrush MediumSlateBlue => KnownColor.MediumSlateBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumSpringGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumSpringGreen { get; private set; }
+        public static ISolidColorBrush MediumSpringGreen => KnownColor.MediumSpringGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumTurquoise"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumTurquoise { get; private set; }
+        public static ISolidColorBrush MediumTurquoise => KnownColor.MediumTurquoise.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MediumVioletRed"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MediumVioletRed { get; private set; }
+        public static ISolidColorBrush MediumVioletRed => KnownColor.MediumVioletRed.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MidnightBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MidnightBlue { get; private set; }
+        public static ISolidColorBrush MidnightBlue => KnownColor.MidnightBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MintCream"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MintCream { get; private set; }
+        public static ISolidColorBrush MintCream => KnownColor.MintCream.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.MistyRose"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush MistyRose { get; private set; }
+        public static ISolidColorBrush MistyRose => KnownColor.MistyRose.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Moccasin"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Moccasin { get; private set; }
+        public static ISolidColorBrush Moccasin => KnownColor.Moccasin.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.NavajoWhite"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush NavajoWhite { get; private set; }
+        public static ISolidColorBrush NavajoWhite => KnownColor.NavajoWhite.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Navy"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Navy { get; private set; }
+        public static ISolidColorBrush Navy => KnownColor.Navy.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.OldLace"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush OldLace { get; private set; }
+        public static ISolidColorBrush OldLace => KnownColor.OldLace.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Olive"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Olive { get; private set; }
+        public static ISolidColorBrush Olive => KnownColor.Olive.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.OliveDrab"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush OliveDrab { get; private set; }
+        public static ISolidColorBrush OliveDrab => KnownColor.OliveDrab.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Orange"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Orange { get; private set; }
+        public static ISolidColorBrush Orange => KnownColor.Orange.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.OrangeRed"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush OrangeRed { get; private set; }
+        public static ISolidColorBrush OrangeRed => KnownColor.OrangeRed.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Orchid"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Orchid { get; private set; }
+        public static ISolidColorBrush Orchid => KnownColor.Orchid.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PaleGoldenrod"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PaleGoldenrod { get; private set; }
+        public static ISolidColorBrush PaleGoldenrod => KnownColor.PaleGoldenrod.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PaleGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PaleGreen { get; private set; }
+        public static ISolidColorBrush PaleGreen => KnownColor.PaleGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PaleTurquoise"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PaleTurquoise { get; private set; }
+        public static ISolidColorBrush PaleTurquoise => KnownColor.PaleTurquoise.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PaleVioletRed"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PaleVioletRed { get; private set; }
+        public static ISolidColorBrush PaleVioletRed => KnownColor.PaleVioletRed.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PapayaWhip"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PapayaWhip { get; private set; }
+        public static ISolidColorBrush PapayaWhip => KnownColor.PapayaWhip.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PeachPuff"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PeachPuff { get; private set; }
+        public static ISolidColorBrush PeachPuff => KnownColor.PeachPuff.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Peru"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Peru { get; private set; }
+        public static ISolidColorBrush Peru => KnownColor.Peru.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Pink"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Pink { get; private set; }
+        public static ISolidColorBrush Pink => KnownColor.Pink.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Plum"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Plum { get; private set; }
+        public static ISolidColorBrush Plum => KnownColor.Plum.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.PowderBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush PowderBlue { get; private set; }
+        public static ISolidColorBrush PowderBlue => KnownColor.PowderBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Purple"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Purple { get; private set; }
+        public static ISolidColorBrush Purple => KnownColor.Purple.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Red"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Red { get; private set; }
+        public static ISolidColorBrush Red => KnownColor.Red.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.RosyBrown"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush RosyBrown { get; private set; }
+        public static ISolidColorBrush RosyBrown => KnownColor.RosyBrown.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.RoyalBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush RoyalBlue { get; private set; }
+        public static ISolidColorBrush RoyalBlue => KnownColor.RoyalBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SaddleBrown"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SaddleBrown { get; private set; }
+        public static ISolidColorBrush SaddleBrown => KnownColor.SaddleBrown.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Salmon"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Salmon { get; private set; }
+        public static ISolidColorBrush Salmon => KnownColor.Salmon.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SandyBrown"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SandyBrown { get; private set; }
+        public static ISolidColorBrush SandyBrown => KnownColor.SandyBrown.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SeaGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SeaGreen { get; private set; }
+        public static ISolidColorBrush SeaGreen => KnownColor.SeaGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SeaShell"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SeaShell { get; private set; }
+        public static ISolidColorBrush SeaShell => KnownColor.SeaShell.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Sienna"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Sienna { get; private set; }
+        public static ISolidColorBrush Sienna => KnownColor.Sienna.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Silver"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Silver { get; private set; }
+        public static ISolidColorBrush Silver => KnownColor.Silver.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SkyBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SkyBlue { get; private set; }
+        public static ISolidColorBrush SkyBlue => KnownColor.SkyBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SlateBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SlateBlue { get; private set; }
+        public static ISolidColorBrush SlateBlue => KnownColor.SlateBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SlateGray"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SlateGray { get; private set; }
+        public static ISolidColorBrush SlateGray => KnownColor.SlateGray.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Snow"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Snow { get; private set; }
+        public static ISolidColorBrush Snow => KnownColor.Snow.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SpringGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SpringGreen { get; private set; }
+        public static ISolidColorBrush SpringGreen => KnownColor.SpringGreen.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.SteelBlue"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush SteelBlue { get; private set; }
+        public static ISolidColorBrush SteelBlue => KnownColor.SteelBlue.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Tan"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Tan { get; private set; }
+        public static ISolidColorBrush Tan => KnownColor.Tan.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Teal"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Teal { get; private set; }
+        public static ISolidColorBrush Teal => KnownColor.Teal.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Thistle"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Thistle { get; private set; }
+        public static ISolidColorBrush Thistle => KnownColor.Thistle.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Tomato"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Tomato { get; private set; }
+        public static ISolidColorBrush Tomato => KnownColor.Tomato.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Transparent"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Transparent { get; private set; }
+        public static ISolidColorBrush Transparent => KnownColor.Transparent.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Turquoise"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Turquoise { get; private set; }
+        public static ISolidColorBrush Turquoise => KnownColor.Turquoise.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Violet"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Violet { get; private set; }
+        public static ISolidColorBrush Violet => KnownColor.Violet.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Wheat"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Wheat { get; private set; }
+        public static ISolidColorBrush Wheat => KnownColor.Wheat.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.White"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush White { get; private set; }
+        public static ISolidColorBrush White => KnownColor.White.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.WhiteSmoke"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush WhiteSmoke { get; private set; }
+        public static ISolidColorBrush WhiteSmoke => KnownColor.WhiteSmoke.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.Yellow"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush Yellow { get; private set; }
+        public static ISolidColorBrush Yellow => KnownColor.Yellow.ToBrush();
 
         /// <summary>
         /// Gets an <see cref="Colors.YellowGreen"/> colored brush.
         /// </summary>
-        public static ISolidColorBrush YellowGreen { get; private set; }
+        public static ISolidColorBrush YellowGreen => KnownColor.YellowGreen.ToBrush();
     }
 }

+ 12 - 15
src/Avalonia.Visuals/Media/Color.cs

@@ -88,6 +88,9 @@ namespace Avalonia.Media
         /// <returns>The <see cref="Color"/>.</returns>
         public static Color Parse(string s)
         {
+            if (s == null) throw new ArgumentNullException(nameof(s));
+            if (s.Length == 0) throw new FormatException();
+
             if (s[0] == '#')
             {
                 var or = 0u;
@@ -103,21 +106,15 @@ namespace Avalonia.Media
 
                 return FromUInt32(uint.Parse(s.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture) | or);
             }
-            else
-            {
-                var upper = s.ToUpperInvariant();
-                var member = typeof(Colors).GetTypeInfo().DeclaredProperties
-                    .FirstOrDefault(x => x.Name.ToUpperInvariant() == upper);
 
-                if (member != null)
-                {
-                    return (Color)member.GetValue(null);
-                }
-                else
-                {
-                    throw new FormatException($"Invalid color string: '{s}'.");
-                }
+            var knownColor = KnownColors.GetKnownColor(s);
+
+            if (knownColor != KnownColor.None)
+            {
+                return knownColor.ToColor();
             }
+
+            throw new FormatException($"Invalid color string: '{s}'.");
         }
 
         /// <summary>
@@ -128,8 +125,8 @@ namespace Avalonia.Media
         /// </returns>
         public override string ToString()
         {
-            uint rgb = ((uint)A << 24) | ((uint)R << 16) | ((uint)G << 8) | (uint)B;
-            return $"#{rgb:x8}";
+            uint rgb = ToUint32();
+            return KnownColors.GetKnownColorName(rgb) ?? $"#{rgb:x8}";
         }
 
         /// <summary>

+ 143 - 141
src/Avalonia.Visuals/Media/Colors.cs

@@ -1,6 +1,8 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using System.Linq;
+
 namespace Avalonia.Media
 {
     /// <summary>
@@ -11,706 +13,706 @@ namespace Avalonia.Media
         /// <summary>
         /// Gets a color with an ARGB value of #fff0f8ff.
         /// </summary>
-        public static Color AliceBlue => Color.FromUInt32(0xfff0f8ff);
+        public static Color AliceBlue => KnownColor.AliceBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffaebd7.
         /// </summary>
-        public static Color AntiqueWhite => Color.FromUInt32(0xfffaebd7);
+        public static Color AntiqueWhite => KnownColor.AntiqueWhite.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00ffff.
         /// </summary>
-        public static Color Aqua => Color.FromUInt32(0xff00ffff);
+        public static Color Aqua => KnownColor.Aqua.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff7fffd4.
         /// </summary>
-        public static Color Aquamarine => Color.FromUInt32(0xff7fffd4);
+        public static Color Aquamarine => KnownColor.Aquamarine.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff0ffff.
         /// </summary>
-        public static Color Azure => Color.FromUInt32(0xfff0ffff);
+        public static Color Azure => KnownColor.Azure.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff5f5dc.
         /// </summary>
-        public static Color Beige => Color.FromUInt32(0xfff5f5dc);
+        public static Color Beige => KnownColor.Beige.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffe4c4.
         /// </summary>
-        public static Color Bisque => Color.FromUInt32(0xffffe4c4);
+        public static Color Bisque => KnownColor.Bisque.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff000000.
         /// </summary>
-        public static Color Black => Color.FromUInt32(0xff000000);
+        public static Color Black => KnownColor.Black.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffebcd.
         /// </summary>
-        public static Color BlanchedAlmond => Color.FromUInt32(0xffffebcd);
+        public static Color BlanchedAlmond => KnownColor.BlanchedAlmond.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff0000ff.
         /// </summary>
-        public static Color Blue => Color.FromUInt32(0xff0000ff);
+        public static Color Blue => KnownColor.Blue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff8a2be2.
         /// </summary>
-        public static Color BlueViolet => Color.FromUInt32(0xff8a2be2);
+        public static Color BlueViolet => KnownColor.BlueViolet.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffa52a2a.
         /// </summary>
-        public static Color Brown => Color.FromUInt32(0xffa52a2a);
+        public static Color Brown => KnownColor.Brown.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdeb887.
         /// </summary>
-        public static Color BurlyWood => Color.FromUInt32(0xffdeb887);
+        public static Color BurlyWood => KnownColor.BurlyWood.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff5f9ea0.
         /// </summary>
-        public static Color CadetBlue => Color.FromUInt32(0xff5f9ea0);
+        public static Color CadetBlue => KnownColor.CadetBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff7fff00.
         /// </summary>
-        public static Color Chartreuse => Color.FromUInt32(0xff7fff00);
+        public static Color Chartreuse => KnownColor.Chartreuse.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffd2691e.
         /// </summary>
-        public static Color Chocolate => Color.FromUInt32(0xffd2691e);
+        public static Color Chocolate => KnownColor.Chocolate.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff7f50.
         /// </summary>
-        public static Color Coral => Color.FromUInt32(0xffff7f50);
+        public static Color Coral => KnownColor.Coral.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff6495ed.
         /// </summary>
-        public static Color CornflowerBlue => Color.FromUInt32(0xff6495ed);
+        public static Color CornflowerBlue => KnownColor.CornflowerBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffff8dc.
         /// </summary>
-        public static Color Cornsilk => Color.FromUInt32(0xfffff8dc);
+        public static Color Cornsilk => KnownColor.Cornsilk.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdc143c.
         /// </summary>
-        public static Color Crimson => Color.FromUInt32(0xffdc143c);
+        public static Color Crimson => KnownColor.Crimson.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00ffff.
         /// </summary>
-        public static Color Cyan => Color.FromUInt32(0xff00ffff);
+        public static Color Cyan => KnownColor.Cyan.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00008b.
         /// </summary>
-        public static Color DarkBlue => Color.FromUInt32(0xff00008b);
+        public static Color DarkBlue => KnownColor.DarkBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff008b8b.
         /// </summary>
-        public static Color DarkCyan => Color.FromUInt32(0xff008b8b);
+        public static Color DarkCyan => KnownColor.DarkCyan.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffb8860b.
         /// </summary>
-        public static Color DarkGoldenrod => Color.FromUInt32(0xffb8860b);
+        public static Color DarkGoldenrod => KnownColor.DarkGoldenrod.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffa9a9a9.
         /// </summary>
-        public static Color DarkGray => Color.FromUInt32(0xffa9a9a9);
+        public static Color DarkGray => KnownColor.DarkGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff006400.
         /// </summary>
-        public static Color DarkGreen => Color.FromUInt32(0xff006400);
+        public static Color DarkGreen => KnownColor.DarkGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffbdb76b.
         /// </summary>
-        public static Color DarkKhaki => Color.FromUInt32(0xffbdb76b);
+        public static Color DarkKhaki => KnownColor.DarkKhaki.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff8b008b.
         /// </summary>
-        public static Color DarkMagenta => Color.FromUInt32(0xff8b008b);
+        public static Color DarkMagenta => KnownColor.DarkMagenta.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff556b2f.
         /// </summary>
-        public static Color DarkOliveGreen => Color.FromUInt32(0xff556b2f);
+        public static Color DarkOliveGreen => KnownColor.DarkOliveGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff8c00.
         /// </summary>
-        public static Color DarkOrange => Color.FromUInt32(0xffff8c00);
+        public static Color DarkOrange => KnownColor.DarkOrange.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff9932cc.
         /// </summary>
-        public static Color DarkOrchid => Color.FromUInt32(0xff9932cc);
+        public static Color DarkOrchid => KnownColor.DarkOrchid.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff8b0000.
         /// </summary>
-        public static Color DarkRed => Color.FromUInt32(0xff8b0000);
+        public static Color DarkRed => KnownColor.DarkRed.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffe9967a.
         /// </summary>
-        public static Color DarkSalmon => Color.FromUInt32(0xffe9967a);
+        public static Color DarkSalmon => KnownColor.DarkSalmon.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff8fbc8f.
         /// </summary>
-        public static Color DarkSeaGreen => Color.FromUInt32(0xff8fbc8f);
+        public static Color DarkSeaGreen => KnownColor.DarkSeaGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff483d8b.
         /// </summary>
-        public static Color DarkSlateBlue => Color.FromUInt32(0xff483d8b);
+        public static Color DarkSlateBlue => KnownColor.DarkSlateBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff2f4f4f.
         /// </summary>
-        public static Color DarkSlateGray => Color.FromUInt32(0xff2f4f4f);
+        public static Color DarkSlateGray => KnownColor.DarkSlateGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00ced1.
         /// </summary>
-        public static Color DarkTurquoise => Color.FromUInt32(0xff00ced1);
+        public static Color DarkTurquoise => KnownColor.DarkTurquoise.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff9400d3.
         /// </summary>
-        public static Color DarkViolet => Color.FromUInt32(0xff9400d3);
+        public static Color DarkViolet => KnownColor.DarkViolet.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff1493.
         /// </summary>
-        public static Color DeepPink => Color.FromUInt32(0xffff1493);
+        public static Color DeepPink => KnownColor.DeepPink.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00bfff.
         /// </summary>
-        public static Color DeepSkyBlue => Color.FromUInt32(0xff00bfff);
+        public static Color DeepSkyBlue => KnownColor.DeepSkyBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff696969.
         /// </summary>
-        public static Color DimGray => Color.FromUInt32(0xff696969);
+        public static Color DimGray => KnownColor.DimGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff1e90ff.
         /// </summary>
-        public static Color DodgerBlue => Color.FromUInt32(0xff1e90ff);
+        public static Color DodgerBlue => KnownColor.DodgerBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffb22222.
         /// </summary>
-        public static Color Firebrick => Color.FromUInt32(0xffb22222);
+        public static Color Firebrick => KnownColor.Firebrick.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffffaf0.
         /// </summary>
-        public static Color FloralWhite => Color.FromUInt32(0xfffffaf0);
+        public static Color FloralWhite => KnownColor.FloralWhite.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff228b22.
         /// </summary>
-        public static Color ForestGreen => Color.FromUInt32(0xff228b22);
+        public static Color ForestGreen => KnownColor.ForestGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff00ff.
         /// </summary>
-        public static Color Fuchsia => Color.FromUInt32(0xffff00ff);
+        public static Color Fuchsia => KnownColor.Fuchsia.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdcdcdc.
         /// </summary>
-        public static Color Gainsboro => Color.FromUInt32(0xffdcdcdc);
+        public static Color Gainsboro => KnownColor.Gainsboro.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff8f8ff.
         /// </summary>
-        public static Color GhostWhite => Color.FromUInt32(0xfff8f8ff);
+        public static Color GhostWhite => KnownColor.GhostWhite.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffd700.
         /// </summary>
-        public static Color Gold => Color.FromUInt32(0xffffd700);
+        public static Color Gold => KnownColor.Gold.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdaa520.
         /// </summary>
-        public static Color Goldenrod => Color.FromUInt32(0xffdaa520);
+        public static Color Goldenrod => KnownColor.Goldenrod.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff808080.
         /// </summary>
-        public static Color Gray => Color.FromUInt32(0xff808080);
+        public static Color Gray => KnownColor.Gray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff008000.
         /// </summary>
-        public static Color Green => Color.FromUInt32(0xff008000);
+        public static Color Green => KnownColor.Green.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffadff2f.
         /// </summary>
-        public static Color GreenYellow => Color.FromUInt32(0xffadff2f);
+        public static Color GreenYellow => KnownColor.GreenYellow.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff0fff0.
         /// </summary>
-        public static Color Honeydew => Color.FromUInt32(0xfff0fff0);
+        public static Color Honeydew => KnownColor.Honeydew.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff69b4.
         /// </summary>
-        public static Color HotPink => Color.FromUInt32(0xffff69b4);
+        public static Color HotPink => KnownColor.HotPink.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffcd5c5c.
         /// </summary>
-        public static Color IndianRed => Color.FromUInt32(0xffcd5c5c);
+        public static Color IndianRed => KnownColor.IndianRed.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff4b0082.
         /// </summary>
-        public static Color Indigo => Color.FromUInt32(0xff4b0082);
+        public static Color Indigo => KnownColor.Indigo.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffffff0.
         /// </summary>
-        public static Color Ivory => Color.FromUInt32(0xfffffff0);
+        public static Color Ivory => KnownColor.Ivory.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff0e68c.
         /// </summary>
-        public static Color Khaki => Color.FromUInt32(0xfff0e68c);
+        public static Color Khaki => KnownColor.Khaki.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffe6e6fa.
         /// </summary>
-        public static Color Lavender => Color.FromUInt32(0xffe6e6fa);
+        public static Color Lavender => KnownColor.Lavender.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffff0f5.
         /// </summary>
-        public static Color LavenderBlush => Color.FromUInt32(0xfffff0f5);
+        public static Color LavenderBlush => KnownColor.LavenderBlush.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff7cfc00.
         /// </summary>
-        public static Color LawnGreen => Color.FromUInt32(0xff7cfc00);
+        public static Color LawnGreen => KnownColor.LawnGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffffacd.
         /// </summary>
-        public static Color LemonChiffon => Color.FromUInt32(0xfffffacd);
+        public static Color LemonChiffon => KnownColor.LemonChiffon.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffadd8e6.
         /// </summary>
-        public static Color LightBlue => Color.FromUInt32(0xffadd8e6);
+        public static Color LightBlue => KnownColor.LightBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff08080.
         /// </summary>
-        public static Color LightCoral => Color.FromUInt32(0xfff08080);
+        public static Color LightCoral => KnownColor.LightCoral.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffe0ffff.
         /// </summary>
-        public static Color LightCyan => Color.FromUInt32(0xffe0ffff);
+        public static Color LightCyan => KnownColor.LightCyan.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffafad2.
         /// </summary>
-        public static Color LightGoldenrodYellow => Color.FromUInt32(0xfffafad2);
+        public static Color LightGoldenrodYellow => KnownColor.LightGoldenrodYellow.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffd3d3d3.
         /// </summary>
-        public static Color LightGray => Color.FromUInt32(0xffd3d3d3);
+        public static Color LightGray => KnownColor.LightGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff90ee90.
         /// </summary>
-        public static Color LightGreen => Color.FromUInt32(0xff90ee90);
+        public static Color LightGreen => KnownColor.LightGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffb6c1.
         /// </summary>
-        public static Color LightPink => Color.FromUInt32(0xffffb6c1);
+        public static Color LightPink => KnownColor.LightPink.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffa07a.
         /// </summary>
-        public static Color LightSalmon => Color.FromUInt32(0xffffa07a);
+        public static Color LightSalmon => KnownColor.LightSalmon.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff20b2aa.
         /// </summary>
-        public static Color LightSeaGreen => Color.FromUInt32(0xff20b2aa);
+        public static Color LightSeaGreen => KnownColor.LightSeaGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff87cefa.
         /// </summary>
-        public static Color LightSkyBlue => Color.FromUInt32(0xff87cefa);
+        public static Color LightSkyBlue => KnownColor.LightSkyBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff778899.
         /// </summary>
-        public static Color LightSlateGray => Color.FromUInt32(0xff778899);
+        public static Color LightSlateGray => KnownColor.LightSlateGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffb0c4de.
         /// </summary>
-        public static Color LightSteelBlue => Color.FromUInt32(0xffb0c4de);
+        public static Color LightSteelBlue => KnownColor.LightSteelBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffffe0.
         /// </summary>
-        public static Color LightYellow => Color.FromUInt32(0xffffffe0);
+        public static Color LightYellow => KnownColor.LightYellow.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00ff00.
         /// </summary>
-        public static Color Lime => Color.FromUInt32(0xff00ff00);
+        public static Color Lime => KnownColor.Lime.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff32cd32.
         /// </summary>
-        public static Color LimeGreen => Color.FromUInt32(0xff32cd32);
+        public static Color LimeGreen => KnownColor.LimeGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffaf0e6.
         /// </summary>
-        public static Color Linen => Color.FromUInt32(0xfffaf0e6);
+        public static Color Linen => KnownColor.Linen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff00ff.
         /// </summary>
-        public static Color Magenta => Color.FromUInt32(0xffff00ff);
+        public static Color Magenta => KnownColor.Magenta.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff800000.
         /// </summary>
-        public static Color Maroon => Color.FromUInt32(0xff800000);
+        public static Color Maroon => KnownColor.Maroon.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff66cdaa.
         /// </summary>
-        public static Color MediumAquamarine => Color.FromUInt32(0xff66cdaa);
+        public static Color MediumAquamarine => KnownColor.MediumAquamarine.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff0000cd.
         /// </summary>
-        public static Color MediumBlue => Color.FromUInt32(0xff0000cd);
+        public static Color MediumBlue => KnownColor.MediumBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffba55d3.
         /// </summary>
-        public static Color MediumOrchid => Color.FromUInt32(0xffba55d3);
+        public static Color MediumOrchid => KnownColor.MediumOrchid.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff9370db.
         /// </summary>
-        public static Color MediumPurple => Color.FromUInt32(0xff9370db);
+        public static Color MediumPurple => KnownColor.MediumPurple.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff3cb371.
         /// </summary>
-        public static Color MediumSeaGreen => Color.FromUInt32(0xff3cb371);
+        public static Color MediumSeaGreen => KnownColor.MediumSeaGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff7b68ee.
         /// </summary>
-        public static Color MediumSlateBlue => Color.FromUInt32(0xff7b68ee);
+        public static Color MediumSlateBlue => KnownColor.MediumSlateBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00fa9a.
         /// </summary>
-        public static Color MediumSpringGreen => Color.FromUInt32(0xff00fa9a);
+        public static Color MediumSpringGreen => KnownColor.MediumSpringGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff48d1cc.
         /// </summary>
-        public static Color MediumTurquoise => Color.FromUInt32(0xff48d1cc);
+        public static Color MediumTurquoise => KnownColor.MediumTurquoise.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffc71585.
         /// </summary>
-        public static Color MediumVioletRed => Color.FromUInt32(0xffc71585);
+        public static Color MediumVioletRed => KnownColor.MediumVioletRed.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff191970.
         /// </summary>
-        public static Color MidnightBlue => Color.FromUInt32(0xff191970);
+        public static Color MidnightBlue => KnownColor.MidnightBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff5fffa.
         /// </summary>
-        public static Color MintCream => Color.FromUInt32(0xfff5fffa);
+        public static Color MintCream => KnownColor.MintCream.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffe4e1.
         /// </summary>
-        public static Color MistyRose => Color.FromUInt32(0xffffe4e1);
+        public static Color MistyRose => KnownColor.MistyRose.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffe4b5.
         /// </summary>
-        public static Color Moccasin => Color.FromUInt32(0xffffe4b5);
+        public static Color Moccasin => KnownColor.Moccasin.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffdead.
         /// </summary>
-        public static Color NavajoWhite => Color.FromUInt32(0xffffdead);
+        public static Color NavajoWhite => KnownColor.NavajoWhite.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff000080.
         /// </summary>
-        public static Color Navy => Color.FromUInt32(0xff000080);
+        public static Color Navy => KnownColor.Navy.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffdf5e6.
         /// </summary>
-        public static Color OldLace => Color.FromUInt32(0xfffdf5e6);
+        public static Color OldLace => KnownColor.OldLace.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff808000.
         /// </summary>
-        public static Color Olive => Color.FromUInt32(0xff808000);
+        public static Color Olive => KnownColor.Olive.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff6b8e23.
         /// </summary>
-        public static Color OliveDrab => Color.FromUInt32(0xff6b8e23);
+        public static Color OliveDrab => KnownColor.OliveDrab.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffa500.
         /// </summary>
-        public static Color Orange => Color.FromUInt32(0xffffa500);
+        public static Color Orange => KnownColor.Orange.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff4500.
         /// </summary>
-        public static Color OrangeRed => Color.FromUInt32(0xffff4500);
+        public static Color OrangeRed => KnownColor.OrangeRed.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffda70d6.
         /// </summary>
-        public static Color Orchid => Color.FromUInt32(0xffda70d6);
+        public static Color Orchid => KnownColor.Orchid.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffeee8aa.
         /// </summary>
-        public static Color PaleGoldenrod => Color.FromUInt32(0xffeee8aa);
+        public static Color PaleGoldenrod => KnownColor.PaleGoldenrod.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff98fb98.
         /// </summary>
-        public static Color PaleGreen => Color.FromUInt32(0xff98fb98);
+        public static Color PaleGreen => KnownColor.PaleGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffafeeee.
         /// </summary>
-        public static Color PaleTurquoise => Color.FromUInt32(0xffafeeee);
+        public static Color PaleTurquoise => KnownColor.PaleTurquoise.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdb7093.
         /// </summary>
-        public static Color PaleVioletRed => Color.FromUInt32(0xffdb7093);
+        public static Color PaleVioletRed => KnownColor.PaleVioletRed.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffefd5.
         /// </summary>
-        public static Color PapayaWhip => Color.FromUInt32(0xffffefd5);
+        public static Color PapayaWhip => KnownColor.PapayaWhip.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffdab9.
         /// </summary>
-        public static Color PeachPuff => Color.FromUInt32(0xffffdab9);
+        public static Color PeachPuff => KnownColor.PeachPuff.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffcd853f.
         /// </summary>
-        public static Color Peru => Color.FromUInt32(0xffcd853f);
+        public static Color Peru => KnownColor.Peru.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffc0cb.
         /// </summary>
-        public static Color Pink => Color.FromUInt32(0xffffc0cb);
+        public static Color Pink => KnownColor.Pink.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffdda0dd.
         /// </summary>
-        public static Color Plum => Color.FromUInt32(0xffdda0dd);
+        public static Color Plum => KnownColor.Plum.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffb0e0e6.
         /// </summary>
-        public static Color PowderBlue => Color.FromUInt32(0xffb0e0e6);
+        public static Color PowderBlue => KnownColor.PowderBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff800080.
         /// </summary>
-        public static Color Purple => Color.FromUInt32(0xff800080);
+        public static Color Purple => KnownColor.Purple.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff0000.
         /// </summary>
-        public static Color Red => Color.FromUInt32(0xffff0000);
+        public static Color Red => KnownColor.Red.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffbc8f8f.
         /// </summary>
-        public static Color RosyBrown => Color.FromUInt32(0xffbc8f8f);
+        public static Color RosyBrown => KnownColor.RosyBrown.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff4169e1.
         /// </summary>
-        public static Color RoyalBlue => Color.FromUInt32(0xff4169e1);
+        public static Color RoyalBlue => KnownColor.RoyalBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff8b4513.
         /// </summary>
-        public static Color SaddleBrown => Color.FromUInt32(0xff8b4513);
+        public static Color SaddleBrown => KnownColor.SaddleBrown.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffa8072.
         /// </summary>
-        public static Color Salmon => Color.FromUInt32(0xfffa8072);
+        public static Color Salmon => KnownColor.Salmon.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff4a460.
         /// </summary>
-        public static Color SandyBrown => Color.FromUInt32(0xfff4a460);
+        public static Color SandyBrown => KnownColor.SandyBrown.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff2e8b57.
         /// </summary>
-        public static Color SeaGreen => Color.FromUInt32(0xff2e8b57);
+        public static Color SeaGreen => KnownColor.SeaGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffff5ee.
         /// </summary>
-        public static Color SeaShell => Color.FromUInt32(0xfffff5ee);
+        public static Color SeaShell => KnownColor.SeaShell.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffa0522d.
         /// </summary>
-        public static Color Sienna => Color.FromUInt32(0xffa0522d);
+        public static Color Sienna => KnownColor.Sienna.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffc0c0c0.
         /// </summary>
-        public static Color Silver => Color.FromUInt32(0xffc0c0c0);
+        public static Color Silver => KnownColor.Silver.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff87ceeb.
         /// </summary>
-        public static Color SkyBlue => Color.FromUInt32(0xff87ceeb);
+        public static Color SkyBlue => KnownColor.SkyBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff6a5acd.
         /// </summary>
-        public static Color SlateBlue => Color.FromUInt32(0xff6a5acd);
+        public static Color SlateBlue => KnownColor.SlateBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff708090.
         /// </summary>
-        public static Color SlateGray => Color.FromUInt32(0xff708090);
+        public static Color SlateGray => KnownColor.SlateGray.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fffffafa.
         /// </summary>
-        public static Color Snow => Color.FromUInt32(0xfffffafa);
+        public static Color Snow => KnownColor.Snow.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff00ff7f.
         /// </summary>
-        public static Color SpringGreen => Color.FromUInt32(0xff00ff7f);
+        public static Color SpringGreen => KnownColor.SpringGreen.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff4682b4.
         /// </summary>
-        public static Color SteelBlue => Color.FromUInt32(0xff4682b4);
+        public static Color SteelBlue => KnownColor.SteelBlue.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffd2b48c.
         /// </summary>
-        public static Color Tan => Color.FromUInt32(0xffd2b48c);
+        public static Color Tan => KnownColor.Tan.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff008080.
         /// </summary>
-        public static Color Teal => Color.FromUInt32(0xff008080);
+        public static Color Teal => KnownColor.Teal.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffd8bfd8.
         /// </summary>
-        public static Color Thistle => Color.FromUInt32(0xffd8bfd8);
+        public static Color Thistle => KnownColor.Thistle.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffff6347.
         /// </summary>
-        public static Color Tomato => Color.FromUInt32(0xffff6347);
+        public static Color Tomato => KnownColor.Tomato.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #00ffffff.
         /// </summary>
-        public static Color Transparent => Color.FromUInt32(0x00ffffff);
+        public static Color Transparent => KnownColor.Transparent.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff40e0d0.
         /// </summary>
-        public static Color Turquoise => Color.FromUInt32(0xff40e0d0);
+        public static Color Turquoise => KnownColor.Turquoise.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffee82ee.
         /// </summary>
-        public static Color Violet => Color.FromUInt32(0xffee82ee);
+        public static Color Violet => KnownColor.Violet.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff5deb3.
         /// </summary>
-        public static Color Wheat => Color.FromUInt32(0xfff5deb3);
+        public static Color Wheat => KnownColor.Wheat.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffffff.
         /// </summary>
-        public static Color White => Color.FromUInt32(0xffffffff);
+        public static Color White => KnownColor.White.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #fff5f5f5.
         /// </summary>
-        public static Color WhiteSmoke => Color.FromUInt32(0xfff5f5f5);
+        public static Color WhiteSmoke => KnownColor.WhiteSmoke.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ffffff00.
         /// </summary>
-        public static Color Yellow => Color.FromUInt32(0xffffff00);
+        public static Color Yellow => KnownColor.Yellow.ToColor();
 
         /// <summary>
         /// Gets a color with an ARGB value of #ff9acd32.
         /// </summary>
-        public static Color YellowGreen => Color.FromUInt32(0xff9acd32);
+        public static Color YellowGreen => KnownColor.YellowGreen.ToColor();
     }
 }

+ 224 - 0
src/Avalonia.Visuals/Media/KnownColors.cs

@@ -0,0 +1,224 @@
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Avalonia.Media
+{
+    internal static class KnownColors
+    {
+        private static readonly IReadOnlyDictionary<string, KnownColor> _knownColorNames;
+        private static readonly IReadOnlyDictionary<uint, string> _knownColors;
+        private static readonly Dictionary<KnownColor, ISolidColorBrush> _knownBrushes;
+
+        static KnownColors()
+        {
+            var knownColorNames = new Dictionary<string, KnownColor>(StringComparer.OrdinalIgnoreCase);
+            var knownColors = new Dictionary<uint, string>();
+
+            foreach (var field in typeof(KnownColor).GetRuntimeFields())
+            {
+                if (field.FieldType != typeof(KnownColor)) continue;
+                var knownColor = (KnownColor)field.GetValue(null);
+                if (knownColor == KnownColor.None) continue;
+
+                knownColorNames.Add(field.Name, knownColor);
+
+                // some known colors have the same value, so use the first
+                if (!knownColors.ContainsKey((uint)knownColor))
+                {
+                    knownColors.Add((uint)knownColor, field.Name);
+                }
+            }
+
+            _knownColorNames = knownColorNames;
+            _knownColors = knownColors;
+            _knownBrushes = new Dictionary<KnownColor, ISolidColorBrush>();
+        }
+
+        public static ISolidColorBrush GetKnownBrush(string s)
+        {
+            var color = GetKnownColor(s);
+            return color != KnownColor.None ? color.ToBrush() : null;
+        }
+
+        public static KnownColor GetKnownColor(string s)
+        {
+            if (_knownColorNames.TryGetValue(s, out var color))
+            {
+                return color;
+            }
+
+            return KnownColor.None;
+        }
+
+        public static string GetKnownColorName(uint rgb)
+        {
+            return _knownColors.TryGetValue(rgb, out var name) ? name : null;
+        }
+
+        public static Color ToColor(this KnownColor color)
+        {
+            return Color.FromUInt32((uint)color);
+        }
+
+        public static ISolidColorBrush ToBrush(this KnownColor color)
+        {
+            lock (_knownBrushes)
+            {
+                if (!_knownBrushes.TryGetValue(color, out var brush))
+                {
+                    brush = new Immutable.ImmutableSolidColorBrush(color.ToColor());
+                    _knownBrushes.Add(color, brush);
+                }
+
+                return brush;
+            }
+        }
+    }
+
+    internal enum KnownColor : uint
+    {
+        None,
+        AliceBlue = 0xfff0f8ff,
+        AntiqueWhite = 0xfffaebd7,
+        Aqua = 0xff00ffff,
+        Aquamarine = 0xff7fffd4,
+        Azure = 0xfff0ffff,
+        Beige = 0xfff5f5dc,
+        Bisque = 0xffffe4c4,
+        Black = 0xff000000,
+        BlanchedAlmond = 0xffffebcd,
+        Blue = 0xff0000ff,
+        BlueViolet = 0xff8a2be2,
+        Brown = 0xffa52a2a,
+        BurlyWood = 0xffdeb887,
+        CadetBlue = 0xff5f9ea0,
+        Chartreuse = 0xff7fff00,
+        Chocolate = 0xffd2691e,
+        Coral = 0xffff7f50,
+        CornflowerBlue = 0xff6495ed,
+        Cornsilk = 0xfffff8dc,
+        Crimson = 0xffdc143c,
+        Cyan = 0xff00ffff,
+        DarkBlue = 0xff00008b,
+        DarkCyan = 0xff008b8b,
+        DarkGoldenrod = 0xffb8860b,
+        DarkGray = 0xffa9a9a9,
+        DarkGreen = 0xff006400,
+        DarkKhaki = 0xffbdb76b,
+        DarkMagenta = 0xff8b008b,
+        DarkOliveGreen = 0xff556b2f,
+        DarkOrange = 0xffff8c00,
+        DarkOrchid = 0xff9932cc,
+        DarkRed = 0xff8b0000,
+        DarkSalmon = 0xffe9967a,
+        DarkSeaGreen = 0xff8fbc8f,
+        DarkSlateBlue = 0xff483d8b,
+        DarkSlateGray = 0xff2f4f4f,
+        DarkTurquoise = 0xff00ced1,
+        DarkViolet = 0xff9400d3,
+        DeepPink = 0xffff1493,
+        DeepSkyBlue = 0xff00bfff,
+        DimGray = 0xff696969,
+        DodgerBlue = 0xff1e90ff,
+        Firebrick = 0xffb22222,
+        FloralWhite = 0xfffffaf0,
+        ForestGreen = 0xff228b22,
+        Fuchsia = 0xffff00ff,
+        Gainsboro = 0xffdcdcdc,
+        GhostWhite = 0xfff8f8ff,
+        Gold = 0xffffd700,
+        Goldenrod = 0xffdaa520,
+        Gray = 0xff808080,
+        Green = 0xff008000,
+        GreenYellow = 0xffadff2f,
+        Honeydew = 0xfff0fff0,
+        HotPink = 0xffff69b4,
+        IndianRed = 0xffcd5c5c,
+        Indigo = 0xff4b0082,
+        Ivory = 0xfffffff0,
+        Khaki = 0xfff0e68c,
+        Lavender = 0xffe6e6fa,
+        LavenderBlush = 0xfffff0f5,
+        LawnGreen = 0xff7cfc00,
+        LemonChiffon = 0xfffffacd,
+        LightBlue = 0xffadd8e6,
+        LightCoral = 0xfff08080,
+        LightCyan = 0xffe0ffff,
+        LightGoldenrodYellow = 0xfffafad2,
+        LightGreen = 0xff90ee90,
+        LightGray = 0xffd3d3d3,
+        LightPink = 0xffffb6c1,
+        LightSalmon = 0xffffa07a,
+        LightSeaGreen = 0xff20b2aa,
+        LightSkyBlue = 0xff87cefa,
+        LightSlateGray = 0xff778899,
+        LightSteelBlue = 0xffb0c4de,
+        LightYellow = 0xffffffe0,
+        Lime = 0xff00ff00,
+        LimeGreen = 0xff32cd32,
+        Linen = 0xfffaf0e6,
+        Magenta = 0xffff00ff,
+        Maroon = 0xff800000,
+        MediumAquamarine = 0xff66cdaa,
+        MediumBlue = 0xff0000cd,
+        MediumOrchid = 0xffba55d3,
+        MediumPurple = 0xff9370db,
+        MediumSeaGreen = 0xff3cb371,
+        MediumSlateBlue = 0xff7b68ee,
+        MediumSpringGreen = 0xff00fa9a,
+        MediumTurquoise = 0xff48d1cc,
+        MediumVioletRed = 0xffc71585,
+        MidnightBlue = 0xff191970,
+        MintCream = 0xfff5fffa,
+        MistyRose = 0xffffe4e1,
+        Moccasin = 0xffffe4b5,
+        NavajoWhite = 0xffffdead,
+        Navy = 0xff000080,
+        OldLace = 0xfffdf5e6,
+        Olive = 0xff808000,
+        OliveDrab = 0xff6b8e23,
+        Orange = 0xffffa500,
+        OrangeRed = 0xffff4500,
+        Orchid = 0xffda70d6,
+        PaleGoldenrod = 0xffeee8aa,
+        PaleGreen = 0xff98fb98,
+        PaleTurquoise = 0xffafeeee,
+        PaleVioletRed = 0xffdb7093,
+        PapayaWhip = 0xffffefd5,
+        PeachPuff = 0xffffdab9,
+        Peru = 0xffcd853f,
+        Pink = 0xffffc0cb,
+        Plum = 0xffdda0dd,
+        PowderBlue = 0xffb0e0e6,
+        Purple = 0xff800080,
+        Red = 0xffff0000,
+        RosyBrown = 0xffbc8f8f,
+        RoyalBlue = 0xff4169e1,
+        SaddleBrown = 0xff8b4513,
+        Salmon = 0xfffa8072,
+        SandyBrown = 0xfff4a460,
+        SeaGreen = 0xff2e8b57,
+        SeaShell = 0xfffff5ee,
+        Sienna = 0xffa0522d,
+        Silver = 0xffc0c0c0,
+        SkyBlue = 0xff87ceeb,
+        SlateBlue = 0xff6a5acd,
+        SlateGray = 0xff708090,
+        Snow = 0xfffffafa,
+        SpringGreen = 0xff00ff7f,
+        SteelBlue = 0xff4682b4,
+        Tan = 0xffd2b48c,
+        Teal = 0xff008080,
+        Thistle = 0xffd8bfd8,
+        Tomato = 0xffff6347,
+        Transparent = 0x00ffffff,
+        Turquoise = 0xff40e0d0,
+        Violet = 0xffee82ee,
+        Wheat = 0xfff5deb3,
+        White = 0xffffffff,
+        WhiteSmoke = 0xfff5f5f5,
+        Yellow = 0xffffff00,
+        YellowGreen = 0xff9acd32
+    }
+}

+ 6 - 10
src/Avalonia.Visuals/Point.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -173,17 +174,12 @@ namespace Avalonia
         /// <returns>The <see cref="Thickness"/>.</returns>
         public static Point Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            if (parts.Count == 2)
-            {
-                return new Point(double.Parse(parts[0], culture), double.Parse(parts[1], culture));
-            }
-            else
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Point"))
             {
-                throw new FormatException("Invalid Point.");
+                return new Point(
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble()
+                );
             }
         }
 

+ 7 - 13
src/Avalonia.Visuals/Rect.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -490,21 +491,14 @@ namespace Avalonia
         /// <returns>The parsed <see cref="Rect"/>.</returns>
         public static Rect Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            if (parts.Count == 4)
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Rect"))
             {
                 return new Rect(
-                    double.Parse(parts[0], culture),
-                    double.Parse(parts[1], culture),
-                    double.Parse(parts[2], culture),
-                    double.Parse(parts[3], culture));
-            }
-            else
-            {
-                throw new FormatException("Invalid Rect.");
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble()
+                );
             }
         }
     }

+ 11 - 15
src/Avalonia.Visuals/RelativePoint.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -157,37 +158,32 @@ namespace Avalonia
         /// <returns>The parsed <see cref="RelativePoint"/>.</returns>
         public static RelativePoint Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            if (parts.Count == 2)
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid RelativePoint"))
             {
+                var x = tokenizer.ReadString();
+                var y = tokenizer.ReadString();
+
                 var unit = RelativeUnit.Absolute;
                 var scale = 1.0;
 
-                if (parts[0].EndsWith("%"))
+                if (x.EndsWith("%"))
                 {
-                    if (!parts[1].EndsWith("%"))
+                    if (!y.EndsWith("%"))
                     {
                         throw new FormatException("If one coordinate is relative, both must be.");
                     }
 
-                    parts[0] = parts[0].TrimEnd('%');
-                    parts[1] = parts[1].TrimEnd('%');
+                    x = x.TrimEnd('%');
+                    y = y.TrimEnd('%');
                     unit = RelativeUnit.Relative;
                     scale = 0.01;
                 }
 
                 return new RelativePoint(
-                    double.Parse(parts[0], culture) * scale,
-                    double.Parse(parts[1], culture) * scale,
+                    double.Parse(x, culture) * scale,
+                    double.Parse(y, culture) * scale,
                     unit);
             }
-            else
-            {
-                throw new FormatException("Invalid Point.");
-            }
         }
     }
 }

+ 29 - 26
src/Avalonia.Visuals/RelativeRect.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -12,6 +13,8 @@ namespace Avalonia
     /// </summary>
     public struct RelativeRect : IEquatable<RelativeRect>
     {
+        private static readonly char[] PercentChar = { '%' };
+
         /// <summary>
         /// A rectangle that represents 100% of an area.
         /// </summary>
@@ -159,7 +162,7 @@ namespace Avalonia
                     Rect.Width * size.Width,
                     Rect.Height * size.Height);
         }
-
+        
         /// <summary>
         /// Parses a <see cref="RelativeRect"/> string.
         /// </summary>
@@ -168,43 +171,43 @@ namespace Avalonia
         /// <returns>The parsed <see cref="RelativeRect"/>.</returns>
         public static RelativeRect Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            if (parts.Count == 4)
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid RelativeRect"))
             {
+                var x = tokenizer.ReadString();
+                var y = tokenizer.ReadString();
+                var width = tokenizer.ReadString();
+                var height = tokenizer.ReadString();
+
                 var unit = RelativeUnit.Absolute;
                 var scale = 1.0;
 
-                if (parts[0].EndsWith("%"))
+                var xRelative = x.EndsWith("%", StringComparison.Ordinal);
+                var yRelative = y.EndsWith("%", StringComparison.Ordinal);
+                var widthRelative = width.EndsWith("%", StringComparison.Ordinal);
+                var heightRelative = height.EndsWith("%", StringComparison.Ordinal);
+
+                if (xRelative && yRelative && widthRelative && heightRelative)
                 {
-                    if (!parts[1].EndsWith("%") 
-                        || !parts[2].EndsWith("%")
-                        || !parts[3].EndsWith("%"))
-                    {
-                        throw new FormatException("If one coordinate is relative, all other must be too.");
-                    }
-
-                    parts[0] = parts[0].TrimEnd('%');
-                    parts[1] = parts[1].TrimEnd('%');
-                    parts[2] = parts[2].TrimEnd('%');
-                    parts[3] = parts[3].TrimEnd('%');
+                    x = x.TrimEnd(PercentChar);
+                    y = y.TrimEnd(PercentChar);
+                    width = width.TrimEnd(PercentChar);
+                    height = height.TrimEnd(PercentChar);
+
                     unit = RelativeUnit.Relative;
                     scale = 0.01;
                 }
+                else if (xRelative || yRelative || widthRelative || heightRelative)
+                {
+                    throw new FormatException("If one coordinate is relative, all must be.");
+                }
 
                 return new RelativeRect(
-                    double.Parse(parts[0], culture) * scale,
-                    double.Parse(parts[1], culture) * scale,
-                    double.Parse(parts[2], culture) * scale,
-                    double.Parse(parts[3], culture) * scale,
+                    double.Parse(x, culture) * scale,
+                    double.Parse(y, culture) * scale,
+                    double.Parse(width, culture) * scale,
+                    double.Parse(height, culture) * scale,
                     unit);
             }
-            else
-            {
-                throw new FormatException("Invalid RelativeRect.");
-            }
         }
     }
 }

+ 5 - 10
src/Avalonia.Visuals/Size.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -153,17 +154,11 @@ namespace Avalonia
         /// <returns>The <see cref="Size"/>.</returns>
         public static Size Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            if (parts.Count == 2)
-            {
-                return new Size(double.Parse(parts[0], culture), double.Parse(parts[1], culture));
-            }
-            else
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Size"))
             {
-                throw new FormatException("Invalid Size.");
+                return new Size(
+                    tokenizer.ReadDouble(),
+                    tokenizer.ReadDouble());
             }
         }
 

+ 15 - 20
src/Avalonia.Visuals/Thickness.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using Avalonia.Utilities;
 using System;
 using System.Globalization;
 using System.Linq;
@@ -168,28 +169,22 @@ namespace Avalonia
         /// <returns>The <see cref="Thickness"/>.</returns>
         public static Thickness Parse(string s, CultureInfo culture)
         {
-            var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
-                .Select(x => x.Trim())
-                .ToList();
-
-            switch (parts.Count)
+            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Thickness"))
             {
-                case 1:
-                    var uniform = double.Parse(parts[0], culture);
-                    return new Thickness(uniform);
-                case 2:
-                    var horizontal = double.Parse(parts[0], culture);
-                    var vertical = double.Parse(parts[1], culture);
-                    return new Thickness(horizontal, vertical);
-                case 4:
-                    var left = double.Parse(parts[0], culture);
-                    var top = double.Parse(parts[1], culture);
-                    var right = double.Parse(parts[2], culture);
-                    var bottom = double.Parse(parts[3], culture);
-                    return new Thickness(left, top, right, bottom);
+                var a = tokenizer.ReadDouble();
+
+                if (tokenizer.TryReadDouble(out var b))
+                {
+                    if (tokenizer.TryReadDouble(out var c))
+                    {
+                        return new Thickness(a, b, c, tokenizer.ReadDouble());
+                    }
+
+                    return new Thickness(a, b);
+                }
+                
+                return new Thickness(a);
             }
-
-            throw new FormatException("Invalid Thickness.");
         }
 
         /// <summary>

+ 15 - 13
src/Gtk/Avalonia.Gtk3/Interop/Native.cs

@@ -263,7 +263,7 @@ namespace Avalonia.Gtk3.Interop
             [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
             public delegate void gtk_window_close(GtkWindow window);
 
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
             public delegate void gtk_window_set_geometry_hints(GtkWindow window, IntPtr geometry_widget, ref GdkGeometry geometry, GdkWindowHints geom_mask);
 
             [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
@@ -502,6 +502,8 @@ namespace Avalonia.Gtk3.Interop
         public static D.cairo_set_font_size CairoSetFontSize;
         public static D.cairo_move_to CairoMoveTo;
         public static D.cairo_destroy CairoDestroy;
+
+        public static D.gtk_window_set_geometry_hints GtkWindowSetGeometryHints;
         public const int G_TYPE_OBJECT = 80;
     }
 
@@ -739,19 +741,19 @@ namespace Avalonia.Gtk3.Interop
     }
 
     [StructLayout(LayoutKind.Sequential)]
-    struct GdkGeometry
+    public struct GdkGeometry
     {
-        gint min_width;
-        gint min_height;
-        gint max_width;
-        gint max_height;
-        gint base_width;
-        gint base_height;
-        gint width_inc;
-        gint height_inc;
-        gdouble min_aspect;
-        gdouble max_aspect;
-        gint win_gravity;
+        public gint min_width;
+        public gint min_height;
+        public gint max_width;
+        public gint max_height;
+        public gint base_width;
+        public gint base_height;
+        public gint width_inc;
+        public gint height_inc;
+        public gdouble min_aspect;
+        public gdouble max_aspect;
+        public gint win_gravity;
     }
 
     enum GdkWindowHints

+ 9 - 0
src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs

@@ -439,6 +439,15 @@ namespace Avalonia.Gtk3
         {
             if (GtkWidget.IsClosed)
                 return;
+
+            GdkGeometry geometry = new GdkGeometry();
+            geometry.min_width = MinWidth > 0 ? (int)MinWidth : -1;
+            geometry.min_height = MinHeight > 0 ? (int)MinHeight : -1;
+            geometry.max_width = !Double.IsInfinity(MaxWidth) && MaxWidth > 0 ? (int)MaxWidth : 999999;
+            geometry.max_height = !Double.IsInfinity(MaxHeight) && MaxHeight > 0 ? (int)MaxHeight : 999999;
+            
+            Native.GtkWindowSetGeometryHints(GtkWidget, IntPtr.Zero, ref geometry, GdkWindowHints.GDK_HINT_MIN_SIZE | GdkWindowHints.GDK_HINT_MAX_SIZE);                
+
             Native.GtkWindowResize(GtkWidget, (int)value.Width, (int)value.Height);
             if (OverrideRedirect)
             {

+ 1 - 2
src/OSX/Avalonia.MonoMac/DragSource.cs

@@ -10,9 +10,8 @@ using System.Runtime.InteropServices;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Threading.Tasks;
 using Avalonia.Controls;
-using Avalonia.Input.DragDrop;
-using Avalonia.Input.Platform;
 using Avalonia.Input;
+using Avalonia.Input.Platform;
 using Avalonia.Input.Raw;
 using MonoMac;
 using MonoMac.AppKit;

+ 1 - 1
src/OSX/Avalonia.MonoMac/DraggingInfo.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using MonoMac.AppKit;
 using MonoMac.Foundation;
 

+ 0 - 2
src/OSX/Avalonia.MonoMac/TopLevelImpl.cs

@@ -1,7 +1,5 @@
 using System;
 using System.Collections.Generic;
-using Avalonia.Input.DragDrop;
-using Avalonia.Input.DragDrop.Raw;
 using Avalonia.Input;
 using Avalonia.Input.Raw;
 using Avalonia.Platform;

+ 1 - 1
src/Windows/Avalonia.Win32/ClipboardFormats.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Linq;
 using System.Text;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Win32.Interop;
 
 namespace Avalonia.Win32

+ 2 - 2
src/Windows/Avalonia.Win32/DataObject.cs

@@ -4,9 +4,9 @@ using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.ComTypes;
 using System.Text;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Win32.Interop;
-using IDataObject = Avalonia.Input.DragDrop.IDataObject;
+using IDataObject = Avalonia.Input.IDataObject;
 using IOleDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;

+ 1 - 1
src/Windows/Avalonia.Win32/DragSource.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Input.Platform;
 using Avalonia.Threading;
 using Avalonia.Win32.Interop;

+ 2 - 2
src/Windows/Avalonia.Win32/OleDataObject.cs

@@ -6,13 +6,13 @@ using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.ComTypes;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text;
-using Avalonia.Input.DragDrop;
+using Avalonia.Input;
 using Avalonia.Win32.Interop;
 using IDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
 
 namespace Avalonia.Win32
 {
-    class OleDataObject : Avalonia.Input.DragDrop.IDataObject
+    class OleDataObject : Avalonia.Input.IDataObject
     {
         private IDataObject _wrapped;
 

+ 3 - 4
src/Windows/Avalonia.Win32/OleDropTarget.cs

@@ -1,9 +1,8 @@
-using Avalonia.Input.DragDrop;
-using Avalonia.Input.DragDrop.Raw;
-using Avalonia.Input;
+using Avalonia.Input;
+using Avalonia.Input.Raw;
 using Avalonia.Platform;
 using Avalonia.Win32.Interop;
-using IDataObject = Avalonia.Input.DragDrop.IDataObject;
+using IDataObject = Avalonia.Input.IDataObject;
 using IOleDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
 
 namespace Avalonia.Win32

+ 4 - 3
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

@@ -8,6 +8,7 @@ using Avalonia.Markup.Xaml.Data;
 using Avalonia.Markup.Xaml.Styling;
 using Avalonia.Markup.Xaml.Templates;
 using Avalonia.Media;
+using Avalonia.Media.Immutable;
 using Avalonia.Styling;
 using Avalonia.UnitTests;
 using System.Collections;
@@ -359,8 +360,8 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
 
             var control = AvaloniaXamlLoader.Parse<UserControl>(xaml);
             var bk = control.Background;
-            Assert.IsType<SolidColorBrush>(bk);
-            Assert.Equal(Colors.White, (bk as SolidColorBrush).Color);
+            Assert.IsType<ImmutableSolidColorBrush>(bk);
+            Assert.Equal(Colors.White, (bk as ISolidColorBrush).Color);
         }
 
         [Fact]
@@ -496,7 +497,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
 
             Assert.NotNull(brush);
 
-            Assert.Equal(Colors.White, ((SolidColorBrush)brush).Color);
+            Assert.Equal(Colors.White, ((ISolidColorBrush)brush).Color);
 
             style.TryGetResource("Double", out var d);
 

+ 14 - 4
tests/Avalonia.Visuals.UnitTests/Media/BrushTests.cs

@@ -12,7 +12,7 @@ namespace Avalonia.Visuals.UnitTests.Media
         [Fact]
         public void Parse_Parses_RGB_Hash_Brush()
         {
-            var result = (SolidColorBrush)Brush.Parse("#ff8844");
+            var result = (ISolidColorBrush)Brush.Parse("#ff8844");
 
             Assert.Equal(0xff, result.Color.R);
             Assert.Equal(0x88, result.Color.G);
@@ -23,7 +23,7 @@ namespace Avalonia.Visuals.UnitTests.Media
         [Fact]
         public void Parse_Parses_ARGB_Hash_Brush()
         {
-            var result = (SolidColorBrush)Brush.Parse("#40ff8844");
+            var result = (ISolidColorBrush)Brush.Parse("#40ff8844");
 
             Assert.Equal(0xff, result.Color.R);
             Assert.Equal(0x88, result.Color.G);
@@ -34,7 +34,7 @@ namespace Avalonia.Visuals.UnitTests.Media
         [Fact]
         public void Parse_Parses_Named_Brush_Lowercase()
         {
-            var result = (SolidColorBrush)Brush.Parse("red");
+            var result = (ISolidColorBrush)Brush.Parse("red");
 
             Assert.Equal(0xff, result.Color.R);
             Assert.Equal(0x00, result.Color.G);
@@ -45,7 +45,7 @@ namespace Avalonia.Visuals.UnitTests.Media
         [Fact]
         public void Parse_Parses_Named_Brush_Uppercase()
         {
-            var result = (SolidColorBrush)Brush.Parse("RED");
+            var result = (ISolidColorBrush)Brush.Parse("RED");
 
             Assert.Equal(0xff, result.Color.R);
             Assert.Equal(0x00, result.Color.G);
@@ -53,6 +53,16 @@ namespace Avalonia.Visuals.UnitTests.Media
             Assert.Equal(0xff, result.Color.A);
         }
 
+        [Fact]
+        public void Parse_ToString_Named_Brush_Roundtrip()
+        {
+            const string expectedName = "Red";
+            var brush = (ISolidColorBrush)Brush.Parse(expectedName);
+            var name = brush.ToString();
+
+            Assert.Equal(expectedName, name);
+        }
+
         [Fact]
         public void Parse_Hex_Value_Doesnt_Accept_Too_Few_Chars()
         {

+ 8 - 0
tests/Avalonia.Visuals.UnitTests/RelativeRectTests.cs

@@ -1,6 +1,7 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using System;
 using System.Globalization;
 using Xunit;
 
@@ -25,5 +26,12 @@ namespace Avalonia.Visuals.UnitTests
 
             Assert.Equal(new RelativeRect(0.1, 0.2, 0.4, 0.7, RelativeUnit.Relative), result, Compare);
         }
+
+        [Fact]
+        public void Parse_Should_Throw_Mixed_Values()
+        {
+            Assert.Throws<FormatException>(() =>
+                RelativeRect.Parse("10%, 20%, 40, 70%", CultureInfo.InvariantCulture));
+        }
     }
 }