# HG changeset patch # User Steven Hollidge # Date 1335017208 -3600 # Node ID 241e2f22ed3c040a3159066c0f80de13c7eef969 # Parent 558c09d767264f66afbd01121903660edabbe56a Latest version diff -r 558c09d76726 -r 241e2f22ed3c SilverlightValidation/Libs/System.Windows.Controls.Data.dll Binary file SilverlightValidation/Libs/System.Windows.Controls.Data.dll has changed diff -r 558c09d76726 -r 241e2f22ed3c SilverlightValidation/Libs/System.Windows.Controls.Navigation.dll Binary file SilverlightValidation/Libs/System.Windows.Controls.Navigation.dll has changed diff -r 558c09d76726 -r 241e2f22ed3c SilverlightValidation/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml Sat Apr 21 15:06:48 2012 +0100 @@ -0,0 +1,9 @@ + + + + + + + diff -r 558c09d76726 -r 241e2f22ed3c SilverlightValidation/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml.cs Sat Apr 21 15:06:48 2012 +0100 @@ -0,0 +1,91 @@ +using System.Reflection; +using System.Windows.Data; +using SilverlightGlimpse.Models; +using System.Windows; +using System.Diagnostics; +using System.Windows.Media; + +namespace SilverlightGlimpse.Controls +{ + public partial class BrokenBindingsViewer + { + public BrokenBindingsViewer() + { + InitializeComponent(); + } + + private void BrokenBindings_Loaded(object sender, RoutedEventArgs e) + { + this.icBrokenBindings.Items.Clear(); + LoadBrokenBindings(GlimpseService.CreateInstance.RootVisual); + } + + private void LoadBrokenBindings(UIElement uiElement) + { + var frameworkElement = uiElement as FrameworkElement; + + if (frameworkElement != null) + { + foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static)) + { + if (object.ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) + { + var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null)); + + if (bindingExpression != null && bindingExpression.ParentBinding.Source == null && bindingExpression.ParentBinding.RelativeSource == null) + { + var isInherited = false; + + if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) + { + foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance)) + { + if (string.Compare(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) == 0) + { + isInherited = true; + break; // TODO: might not be correct. Was : Exit For + } + } + } + + if (isInherited) + { + break; // TODO: might not be correct. Was : Exit For + } + + //this code handles empty bindings on the Button controls + //I'll have to look into why the Button has an empty or unresolved binding + if (string.IsNullOrEmpty(frameworkElement.Name) + && frameworkElement.GetType().Name == "TextBlock" + && fieldInfo.Name == "TextProperty" + && string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) + { + break; // TODO: might not be correct. Was : Exit For + } + + BrokenBinding objBrokenBinding = new BrokenBinding( + frameworkElement.Name, + frameworkElement.GetType().Name, + fieldInfo.Name, + bindingExpression.ParentBinding.Path.Path); + this.icBrokenBindings.Items.Add(objBrokenBinding); + Debug.WriteLine("Broken Binding - ", objBrokenBinding.ToString()); + } + } + } + + int children = VisualTreeHelper.GetChildrenCount(frameworkElement); + + for (int j = 0; j <= children - 1; j++) + { + FrameworkElement child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement; + + if (child != null) + { + LoadBrokenBindings(child); + } + } + } + } + } +} \ No newline at end of file diff -r 558c09d76726 -r 241e2f22ed3c SilverlightValidation/SilverlightGlimpse/Controls/ExceptionsViewer.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightGlimpse/Controls/ExceptionsViewer.xaml Sat Apr 21 15:06:48 2012 +0100 @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +