changeset 75:c01dd64f078b

Fixed false positive on the int values
author Steven Hollidge <stevenhollidge@hotmail.com>
date Mon, 23 Apr 2012 21:29:47 +0100
parents a79e235177f5
children 441fdfce70a7
files SilverlightGlimpse/SilverlightGlimpse/Bugs.txt SilverlightGlimpse/SilverlightGlimpse/Diagnostics/PropertyPathHelper.cs SilverlightGlimpse/SilverlightGlimpse/Services/BrokenBindingsService.cs SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml.cs
diffstat 6 files changed, 60 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/SilverlightGlimpse/SilverlightGlimpse/Bugs.txt	Mon Apr 23 20:29:55 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/Bugs.txt	Mon Apr 23 21:29:47 2012 +0100
@@ -1,2 +1,2 @@
-Mutex for silverlight in debugmonitor
-Refactor out the ValidationWrapper
\ No newline at end of file
+Colours for the numbers
+Numbers on tab headers
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SilverlightGlimpse/SilverlightGlimpse/Diagnostics/PropertyPathHelper.cs	Mon Apr 23 21:29:47 2012 +0100
@@ -0,0 +1,23 @@
+using System.Windows;
+using System.Windows.Data;
+
+namespace SilverlightGlimpse.Diagnostics
+{
+    public static class PropertyPathHelper
+    {
+        public static object GetValue(object source, string propertyPath)
+        {
+            Binding binding = new Binding(propertyPath) {Mode = BindingMode.OneTime, Source = source};
+            BindingOperations.SetBinding(_dummy, Dummy.ValueProperty, binding);
+            return _dummy.GetValue(Dummy.ValueProperty);
+        }
+
+        private static readonly Dummy _dummy = new Dummy();
+
+        private class Dummy : DependencyObject
+        {
+            public static readonly DependencyProperty ValueProperty =
+                DependencyProperty.Register("Value", typeof (object), typeof (Dummy), new PropertyMetadata(null));
+        }
+    }
+}
--- a/SilverlightGlimpse/SilverlightGlimpse/Services/BrokenBindingsService.cs	Mon Apr 23 20:29:55 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/Services/BrokenBindingsService.cs	Mon Apr 23 21:29:47 2012 +0100
@@ -4,6 +4,7 @@
 using System.Reflection;
 using System.Windows;
 using System.Windows.Media;
+using SilverlightGlimpse.Diagnostics;
 using SilverlightGlimpse.Interfaces;
 using SilverlightGlimpse.Models;
 
@@ -13,25 +14,25 @@
     {
         public void LoadBrokenBindings(UIElement uiElement, IList<BindingError> bindingErrors)
         {
-            var frameworkElement = uiElement as FrameworkElement;
-            if (frameworkElement == null) return;
+            var fe = uiElement as FrameworkElement;
+            if (fe == null) return;
 
-            foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static))
+            foreach (var fi in fe.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static))
             {
-                if (!ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) continue;
+                if (!ReferenceEquals(fi.FieldType, typeof(DependencyProperty))) continue;
 
-                var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null));
+                var be = fe.GetBindingExpression((DependencyProperty)fi.GetValue(null));
 
-                if (bindingExpression == null || bindingExpression.ParentBinding.Source != null ||
-                    bindingExpression.ParentBinding.RelativeSource != null) continue;
+                if (be == null || be.ParentBinding.Source != null ||
+                    be.ParentBinding.RelativeSource != null) continue;
 
                 var isInherited = false;
 
-                if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path))
+                if (fe.DataContext != null && !string.IsNullOrEmpty(be.ParentBinding.Path.Path))
                 {
-                    foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance))
+                    foreach (var propertyInfo in fe.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance))
                     {
-                        if (String.CompareOrdinal(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) != 0) continue;
+                        if (String.Compare(propertyInfo.Name, be.ParentBinding.Path.Path) != 0) continue;
                         isInherited = true;
                         break;
                     }
@@ -41,29 +42,32 @@
 
                 //this code handles empty bindings on the Button controls
                 // unsure as to why the Button has an empty or unresolved binding of textblock type...
-                if ((frameworkElement.Name == "")
-                    && (frameworkElement.GetType().Name == "TextBlock")
-                    && (fieldInfo.Name == "TextProperty")
-                    && (bindingExpression.ParentBinding.Path.Path == ""))
+                if ((fe.Name == "")
+                    && (fe.GetType().Name == "TextBlock")
+                    && (fi.Name == "TextProperty")
+                    && (be.ParentBinding.Path.Path == ""))
                 {
                     continue;
                 }
 
+                if (PropertyPathHelper.GetValue(fe, "Text").ToString() != string.Empty)
+                    continue;
+
                 var brokenBinding = new BindingError(
-                    frameworkElement.Name,
-                    frameworkElement.GetType().Name,
-                    fieldInfo.Name,
-                    bindingExpression.ParentBinding.Path.Path);
+                    fe.Name,
+                    fe.GetType().Name,
+                    fi.Name,
+                    be.ParentBinding.Path.Path);
 
                 bindingErrors.Add(brokenBinding);
                 Debug.WriteLine("Broken Binding: {0}", brokenBinding);
             }
 
-            int children = VisualTreeHelper.GetChildrenCount(frameworkElement);
+            int children = VisualTreeHelper.GetChildrenCount(fe);
 
             for (int j = 0; j <= children - 1; j++)
             {
-                var child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement;
+                var child = VisualTreeHelper.GetChild(fe, j) as FrameworkElement;
 
                 if (child != null)
                 {
--- a/SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj	Mon Apr 23 20:29:55 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj	Mon Apr 23 21:29:47 2012 +0100
@@ -70,6 +70,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Diagnostics\PropertyPathHelper.cs" />
     <Compile Include="Services\BrokenBindingsService.cs" />
     <Compile Include="Interfaces\IBrokenBindingsService.cs" />
     <Compile Include="Interfaces\ILogWriter.cs" />
--- a/SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml	Mon Apr 23 20:29:55 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml	Mon Apr 23 21:29:47 2012 +0100
@@ -61,11 +61,12 @@
                         VerticalAlignment="Top"
                         Orientation="Horizontal">
                 <Button x:Name="btnClear"
-                        Width="30"
+                        Width="60"
                         Click="btnClear_Click"
                         Content="Clear" />
 
                 <Button x:Name="btnContract"
+                        Width="60"
                         Margin="10,0,0,0"
                         Click="btnContract_Click"
                         Content="Contract" />
--- a/SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml.cs	Mon Apr 23 20:29:55 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/Views/GlimpseViewer.xaml.cs	Mon Apr 23 21:29:47 2012 +0100
@@ -1,4 +1,6 @@
 using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
 using SilverlightGlimpse.Services;
 
 namespace SilverlightGlimpse.Views
@@ -11,6 +13,12 @@
             DataContext = Glimpse.Service;
         }
 
+        private void AddBinding(FrameworkElement control, object source)
+        {
+            Binding binding = new Binding() {Source = source};
+            control.SetBinding(TextBlock.TextProperty, binding);
+        }
+
         private void btnContract_Click(object sender, RoutedEventArgs e)
         {
             layoutViewer.Visibility = Visibility.Collapsed;