comparison Glimpse/Glimpse Controls/BrokenBindingsViewer.xaml.vb @ 59:3591c26bd63e

MVVMLight added
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 19:20:28 +0100
parents
children
comparison
equal deleted inserted replaced
58:241e2f22ed3c 59:3591c26bd63e
1 Imports System.Reflection
2 Imports System.Windows.Data
3 Partial Public Class BrokenBindingsViewer
4 Inherits UserControl
5
6 Public Sub New()
7 InitializeComponent()
8 End Sub
9
10 Private Sub BrokenBindings_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
11 Me.icBrokenBindings.Items.Clear()
12 LoadBrokenBindings(GlimpseService.CreateInstance.RootVisual)
13 End Sub
14
15 Private Sub LoadBrokenBindings(ByVal uie As UIElement)
16
17 Dim fwe As FrameworkElement = TryCast(uie, FrameworkElement)
18
19 If fwe IsNot Nothing Then
20
21 For Each fi As FieldInfo In fwe.GetType.GetFields(BindingFlags.Public Or BindingFlags.FlattenHierarchy Or BindingFlags.Instance Or BindingFlags.Static)
22
23 If fi.FieldType Is GetType(DependencyProperty) Then
24
25 Dim be As BindingExpression = fwe.GetBindingExpression(DirectCast(fi.GetValue(Nothing), DependencyProperty))
26
27 If be IsNot Nothing AndAlso be.ParentBinding.Source Is Nothing AndAlso be.ParentBinding.RelativeSource Is Nothing Then
28
29 Dim bolIsInherited As Boolean = False
30
31 If fwe.DataContext IsNot Nothing AndAlso Not String.IsNullOrEmpty(be.ParentBinding.Path.Path) Then
32
33 For Each p As PropertyInfo In fwe.DataContext.GetType.GetProperties(BindingFlags.Public Or BindingFlags.FlattenHierarchy Or BindingFlags.Static Or BindingFlags.Instance)
34
35 If String.Compare(p.Name, be.ParentBinding.Path.Path) = 0 Then
36 bolIsInherited = True
37 Exit For
38 End If
39
40 Next
41
42 End If
43
44 If bolIsInherited Then
45 Exit For
46 End If
47
48 'this code handles empty bindings on the Button controls
49 'I'll have to look into why the Button has an empty or unresolved binding
50 If fwe.Name = "" AndAlso fwe.GetType.Name = "TextBlock" AndAlso fi.Name = "TextProperty" AndAlso be.ParentBinding.Path.Path = "" Then
51 Exit For
52 End If
53
54 Dim objBrokenBinding As New BrokenBinding(fwe.Name, fwe.GetType.Name, fi.Name, be.ParentBinding.Path.Path)
55 Me.icBrokenBindings.Items.Add(objBrokenBinding)
56 System.Diagnostics.Debug.WriteLine(String.Format("Broken Binding - ", objBrokenBinding.ToString))
57 End If
58
59 End If
60
61 Next
62
63 Dim children As Integer = VisualTreeHelper.GetChildrenCount(fwe)
64
65 For intX As Integer = 0 To children - 1
66
67 Dim child As FrameworkElement = TryCast(VisualTreeHelper.GetChild(fwe, intX), FrameworkElement)
68
69 If child IsNot Nothing Then
70 LoadBrokenBindings(child)
71 End If
72
73 Next
74
75 End If
76
77 End Sub
78
79 End Class