Mercurial > silverbladetech
comparison delete me/Glimpse/Glimpse Services/GlimpseService.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.Diagnostics | |
2 Imports System.Collections.ObjectModel | |
3 Imports System.ComponentModel | |
4 | |
5 Public Class GlimpseService | |
6 | |
7 #Region " Declarations " | |
8 | |
9 Private Shared _instance As GlimpseService | |
10 Private _objGlimpseWindow As ChildWindow | |
11 Private _objHostExceptions As New ObservableCollection(Of ExceptionWrapper) | |
12 Private _strHostApplicationName As String = String.Empty | |
13 Private WithEvents _objApp As Application | |
14 Private WithEvents _objRootVisual As FrameworkElement | |
15 | |
16 #End Region | |
17 | |
18 #Region " Properties " | |
19 | |
20 Public Shared ReadOnly Property CreateInstance() As GlimpseService | |
21 Get | |
22 | |
23 If _instance Is Nothing Then | |
24 _instance = New GlimpseService | |
25 End If | |
26 | |
27 Return _instance | |
28 End Get | |
29 End Property | |
30 | |
31 Friend Property App() As Application | |
32 Get | |
33 Return _objApp | |
34 End Get | |
35 Set(ByVal Value As Application) | |
36 _objApp = Value | |
37 End Set | |
38 End Property | |
39 | |
40 Friend Property GlimpseWindow() As ChildWindow | |
41 Get | |
42 Return _objGlimpseWindow | |
43 End Get | |
44 | |
45 Private Set(ByVal Value As ChildWindow) | |
46 _objGlimpseWindow = Value | |
47 End Set | |
48 End Property | |
49 | |
50 Friend Property HostApplicationName() As String | |
51 Get | |
52 Return _strHostApplicationName | |
53 End Get | |
54 Set(ByVal Value As String) | |
55 _strHostApplicationName = Value | |
56 End Set | |
57 End Property | |
58 | |
59 Friend ReadOnly Property HostExceptions() As ObservableCollection(Of ExceptionWrapper) | |
60 Get | |
61 Return _objHostExceptions | |
62 End Get | |
63 End Property | |
64 | |
65 Friend Property RootVisual() As FrameworkElement | |
66 Get | |
67 Return _objRootVisual | |
68 End Get | |
69 Set(ByVal Value As FrameworkElement) | |
70 _objRootVisual = Value | |
71 End Set | |
72 End Property | |
73 | |
74 #End Region | |
75 | |
76 #Region " Creation and Loading " | |
77 | |
78 Public Sub DisplayLoadFailure(ByVal objApp As Application, ByVal ex As Exception, ByVal strHostApplicationName As String) | |
79 Debug.WriteLine(String.Format("{0} had exception. {1}", Me.HostApplicationName, ex.ToString)) | |
80 _objApp = objApp | |
81 _objApp.RootVisual = New LoadExceptionViewer(ex, strHostApplicationName) | |
82 End Sub | |
83 | |
84 Public Sub Load(ByVal objApp As Application, ByVal strHostApplicationName As String) | |
85 Me.App = objApp | |
86 Me.RootVisual = TryCast(objApp.RootVisual, FrameworkElement) | |
87 Me.HostApplicationName = strHostApplicationName | |
88 | |
89 Dim fw As New ChildWindow | |
90 fw.Title = Me.HostApplicationName | |
91 fw.Content = New GlimpseViewer | |
92 fw.Show() | |
93 | |
94 'If Double.IsNaN(Me.RootVisual.Width) Then | |
95 ' 'if the host control is autosized (consumes the browser window) then locate Glimpse in the top, left | |
96 ' fw.Show() | |
97 'Else | |
98 ' 'if the host is fixed size then attempt to locate the popup control in the upper right corner | |
99 ' Dim dblLeft As Double = Me.RootVisual.Width - 200 | |
100 | |
101 ' If dblLeft < 0 Then | |
102 ' dblLeft = 0 | |
103 ' End If | |
104 | |
105 ' fw.Show() | |
106 'End If | |
107 | |
108 End Sub | |
109 | |
110 Private Sub New() | |
111 End Sub | |
112 | |
113 #End Region | |
114 | |
115 #Region " Host Application Events " | |
116 | |
117 Private Sub _objHostRootVisual_BindingValidationError(ByVal sender As Object, ByVal e As System.Windows.Controls.ValidationErrorEventArgs) Handles _objRootVisual.BindingValidationError | |
118 | |
119 Dim strControlName As String = "(none)" | |
120 Dim objControl As Control = TryCast(e.OriginalSource, Control) | |
121 | |
122 If objControl IsNot Nothing AndAlso Not String.IsNullOrEmpty(objControl.Name) Then | |
123 strControlName = objControl.Name | |
124 End If | |
125 | |
126 Dim ex As Exception = e.Error.Exception | |
127 | |
128 While ex IsNot Nothing | |
129 Me.HostExceptions.Add(New ExceptionWrapper(e.Action, strControlName, e.Error.Exception)) | |
130 ex = ex.InnerException | |
131 End While | |
132 | |
133 End Sub | |
134 | |
135 Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles _objApp.UnhandledException | |
136 Debug.WriteLine(String.Format("{0} had exception. {1}", Me.HostApplicationName, e.ExceptionObject.ToString)) | |
137 | |
138 Dim ex As Exception = e.ExceptionObject | |
139 | |
140 While ex IsNot Nothing | |
141 Me.HostExceptions.Add(New ExceptionWrapper(ex)) | |
142 ex = ex.InnerException | |
143 End While | |
144 | |
145 e.Handled = True | |
146 End Sub | |
147 | |
148 #End Region | |
149 | |
150 End Class |