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