diff --git a/Perspex/Diagnostics/Debug.cs b/Perspex/Diagnostics/Debug.cs new file mode 100644 index 0000000000..33942f9137 --- /dev/null +++ b/Perspex/Diagnostics/Debug.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Perspex.Diagnostics +{ + public static class Debug + { + public static string PrintVisualTree(IVisual visual) + { + StringBuilder result = new StringBuilder(); + PrintVisualTree(visual, result, 0); + return result.ToString(); + } + + private static void PrintVisualTree(IVisual visual, StringBuilder builder, int indent) + { + builder.Append(Indent(indent - 1)); + + if (indent > 0) + { + builder.Append(" +- "); + } + + builder.AppendLine(visual.GetType().Name); + + PerspexObject p = visual as PerspexObject; + + if (p != null) + { + foreach (var value in p.GetSetValues()) + { + builder.Append(Indent(indent)); + builder.Append(" | "); + builder.Append(value.Item1.Name); + builder.Append(" = "); + builder.Append(value.Item2); + builder.Append(" ("); + builder.Append(value.Item3); + builder.AppendLine(")"); + } + } + + foreach (var child in visual.VisualChildren) + { + PrintVisualTree(child, builder, indent + 1); + } + } + + private static string Indent(int indent) + { + return string.Join("", Enumerable.Repeat(" ", Math.Max(indent, 0))); + } + } +} diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index 9c5ef2371b..402e7e426b 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -94,6 +94,7 @@ + diff --git a/Perspex/PerspexObject.cs b/Perspex/PerspexObject.cs index 061c2a350b..c3aaab4365 100644 --- a/Perspex/PerspexObject.cs +++ b/Perspex/PerspexObject.cs @@ -321,6 +321,20 @@ namespace Perspex return (T)this.GetValue((PerspexProperty)property); } + /// + /// Gets all of the values explicitly set on this object. + /// + public IEnumerable> GetSetValues() + { + foreach (var value in this.values) + { + yield return Tuple.Create( + value.Key, + value.Value.Value, + (BindingPriority)value.Value.ValuePriority); + } + } + /// /// Checks whether a is set on this object. /// diff --git a/Perspex/PriorityValue.cs b/Perspex/PriorityValue.cs index 80d9bbc4e2..5bcc2c314b 100644 --- a/Perspex/PriorityValue.cs +++ b/Perspex/PriorityValue.cs @@ -40,17 +40,13 @@ namespace Perspex /// private object value; - /// - /// The priority of the binding that is currently active. - /// - private int valuePriority = int.MaxValue; - /// /// Initializes a new instance of the class. /// public PriorityValue() { this.value = PerspexProperty.UnsetValue; + this.ValuePriority = int.MaxValue; } /// @@ -69,6 +65,15 @@ namespace Perspex get { return this.value; } } + /// + /// Gets the priority of the binding that is currently active. + /// + public int ValuePriority + { + get; + private set; + } + /// /// Adds a new binding. /// @@ -127,7 +132,7 @@ namespace Perspex item = next; } - if (removed && priority <= this.valuePriority) + if (removed && priority <= this.ValuePriority) { this.UpdateValue(); } @@ -148,7 +153,7 @@ namespace Perspex /// The changed entry. private void EntryChanged(BindingEntry changed) { - if (changed.Priority <= this.valuePriority) + if (changed.Priority <= this.ValuePriority) { this.UpdateValue(); } @@ -172,7 +177,7 @@ namespace Perspex { object old = this.value; - this.valuePriority = priority; + this.ValuePriority = priority; if (!EqualityComparer.Default.Equals(old, value)) { diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 74d160b3b1..3f2cf9a9e0 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -82,6 +82,8 @@ namespace TestApplication } }; + System.Console.WriteLine(Perspex.Diagnostics.Debug.PrintVisualTree(window)); + window.Show(); Dispatcher.Run(); }