From c77ee3aa47f4bd80c085e10055f1d40884b70fe0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 2 Sep 2015 20:48:14 +0200 Subject: [PATCH 001/223] Prevent IndexOutOfRangeException in data binding. --- .../DataBinding/ChangeTracking/ObservablePropertyBranch.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs b/src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs index d1bf21a8b4d..2df9a766f3f 100644 --- a/src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs +++ b/src/Markup/Perspex.Markup.Xaml/DataBinding/ChangeTracking/ObservablePropertyBranch.cs @@ -66,7 +66,11 @@ private IEnumerable GetSubscriptionsRecursive(object current, Property var currentObjectTypeInfo = current.GetType().GetTypeInfo(); var nextProperty = currentObjectTypeInfo.GetDeclaredProperty(nextPropertyName); var nextInstance = nextProperty.GetValue(current); - subscriptions.AddRange(this.GetSubscriptionsRecursive(nextInstance, propertyPath, i + 1)); + + if (i < this.propertyPath.Chunks.Length - 1) + { + subscriptions.AddRange(this.GetSubscriptionsRecursive(nextInstance, propertyPath, i + 1)); + } } return subscriptions; From 24d65b54f8a3fb30df6542973ec60d0216a264a4 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 2 Sep 2015 21:30:07 +0200 Subject: [PATCH 002/223] Accept named brushes in XAML. --- .../Converters/BrushConverter.cs | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs b/src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs index cd55031cf78..63efc9f5c1a 100644 --- a/src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs +++ b/src/Markup/Perspex.Markup.Xaml/Converters/BrushConverter.cs @@ -8,6 +8,7 @@ namespace Perspex.Markup.Xaml.Converters { using System; using System.Globalization; + using System.Reflection; using System.Text; using Media; using Media.Imaging; @@ -32,10 +33,24 @@ public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture var color = DecodeColor(colorString); - return new SolidColorBrush(color); + if (color != null) + { + return new SolidColorBrush(color.Value); + } + else + { + var member = typeof(Brushes).GetTypeInfo().GetDeclaredProperty(colorString); + + if (member != null) + { + return (Brush)member.GetValue(null); + } + } + + throw new InvalidOperationException("Invalid color string."); } - private static Color DecodeColor(string colorString) + private static Color? DecodeColor(string colorString) { if (colorString[0] == '#') { @@ -49,6 +64,7 @@ private static Color DecodeColor(string colorString) var b = Convert.ToByte(restOfValue.Substring(8, 2), 16); return Color.FromArgb(a, r, g, b); } + if (restOfValue.Length == 6) { var r = Convert.ToByte(restOfValue.Substring(0, 2), 16); @@ -59,26 +75,8 @@ private static Color DecodeColor(string colorString) throw new InvalidOperationException("The color code format cannot be parsed"); } - else - { - return DecodeFromNamedColor(colorString); - } - - throw new InvalidOperationException($"The color cannot be decoded from the string \"{colorString}\""); - } - private static Color DecodeFromNamedColor(string colorString) - { - if (colorString == "Crimson") - { - return DecodeColor("#DC143C"); - } - if (colorString == "Coral") - { - return DecodeColor("#FF7F50"); - } - - throw new NotImplementedException(); + return null; } public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType) From c88d716ea6697c23d9165f91d728e0349ee043a9 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 2 Sep 2015 21:30:35 +0200 Subject: [PATCH 003/223] Allow space as separator in Thickness in XAML. --- src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs b/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs index 061618f55f2..6f2c85ae7ef 100644 --- a/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs +++ b/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs @@ -27,7 +27,7 @@ public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture private static Thickness ConvertFromString(string s) { - var parts = s.Split(',') + var parts = s.Split(',', ' ') .Take(4) .Select(part => part.Trim()); From 9c240db51c1b675bb13062864634dc97a16065f1 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 2 Sep 2015 21:36:30 +0200 Subject: [PATCH 004/223] Handle X,Y thicknesses in XAML. --- .../Converters/ThicknessConverter.cs | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs b/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs index 6f2c85ae7ef..d1fc66f16f8 100644 --- a/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs +++ b/src/Markup/Perspex.Markup.Xaml/Converters/ThicknessConverter.cs @@ -27,35 +27,26 @@ public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture private static Thickness ConvertFromString(string s) { - var parts = s.Split(',', ' ') - .Take(4) - .Select(part => part.Trim()); + var parts = s.Split(',', ' '); - if (parts.Count() == 1) + switch (parts.Length) { - var uniformLength = double.Parse(parts.First()); - return new Thickness(uniformLength); + case 1: + var uniform = double.Parse(parts[0]); + return new Thickness(uniform); + case 2: + var horizontal = double.Parse(parts[0]); + var vertical = double.Parse(parts[1]); + return new Thickness(horizontal, vertical); + case 4: + var left = double.Parse(parts[0]); + var top = double.Parse(parts[1]); + var right = double.Parse(parts[2]); + var bottom = double.Parse(parts[3]); + return new Thickness(left, top, right, bottom); } - double left = 0, top = 0, right = 0, bottom = 0; - - IList> setValue = new List> - { - val => left = val, - val => top = val, - val => right = val, - val => bottom = val, - }; - - var i = 0; - foreach (var part in parts) - { - var v = double.Parse(part); - setValue[i](v); - i++; - } - - return new Thickness(left, top, right, bottom); + throw new InvalidOperationException("Invalid Thickness."); } public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType) From 16b47e222cbad28e9d4b3a5af634f881ba445b88 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 2 Sep 2015 21:54:53 +0200 Subject: [PATCH 005/223] Fixed Button style a bit. --- src/Perspex.Themes.Default/ButtonStyle.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Perspex.Themes.Default/ButtonStyle.cs b/src/Perspex.Themes.Default/ButtonStyle.cs index 0c5db083a74..33f284ed399 100644 --- a/src/Perspex.Themes.Default/ButtonStyle.cs +++ b/src/Perspex.Themes.Default/ButtonStyle.cs @@ -29,16 +29,6 @@ public ButtonStyle() this.AddRange(new[] { new Style(x => x.OfType