annotate Glimpse/Glimpse Controls/BrokenBindingsViewer.xaml.vb @ 82:352ecaa4fcfd

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