Bonjour,

Je travail sur une application silverlight. Je souhaite intégrer un composant développé en C#. J'ai, bien sur, la possibilité d'intégrer directement le projet tel quel, mais je souhaiterai le traduire en VB.NET.

Il s'agit du projet suivant :
http://shemesh.wordpress.com/2010/07...E2%80%93-best/

Le code traduit se compile mais le control ne fonctionne pas.

(J'aimerai surtout traduire la classe du control en question.)

Merci de votre aide.

Ma traduction :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Controls.Primitives
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
 
 
 
 
''' <summary>
''' Specifies different collapse modes of a _3GRCGridSplitterAdvanced.
''' </summary>
Public Enum GridSplitterCollapseMode
    ''' <summary>
    ''' The _3GRCGridSplitterAdvanced cannot be collapsed or expanded.
    ''' </summary>
    None = 0
    ''' <summary>
    ''' The column (or row) to the right (or below) the
    ''' splitter's column, will be collapsed.
    ''' </summary>
    [Next] = 1
    ''' <summary>
    ''' The column (or row) to the left (or above) the
    ''' splitter's column, will be collapsed.
    ''' </summary>
    Previous = 2
End Enum
 
 
''' <summary>
''' An updated version of the standard _3GRCGridSplitterAdvanced control that includes a centered handle
''' which allows complete collapsing and expanding of the appropriate grid column or row.
''' </summary>
<TemplatePart(Name:=_3GRCGridSplitterAdvanced.ELEMENT_HORIZONTAL_HANDLE_NAME, Type:=GetType(ToggleButton))> _
<TemplatePart(Name:=_3GRCGridSplitterAdvanced.ELEMENT_VERTICAL_HANDLE_NAME, Type:=GetType(ToggleButton))> _
<TemplatePart(Name:=_3GRCGridSplitterAdvanced.ELEMENT_HORIZONTAL_TEMPLATE_NAME, Type:=GetType(FrameworkElement))> _
<TemplatePart(Name:=_3GRCGridSplitterAdvanced.ELEMENT_VERTICAL_TEMPLATE_NAME, Type:=GetType(FrameworkElement))> _
Public Class _3GRCGridSplitterAdvanced
    Inherits System.Windows.Controls.GridSplitter
 
#Region "TemplateParts"
 
    Public Const ELEMENT_HORIZONTAL_HANDLE_NAME As String = "HorizontalGridSplitterHandle"
    Public Const ELEMENT_VERTICAL_HANDLE_NAME As String = "VerticalGridSplitterHandle"
    Public Const ELEMENT_HORIZONTAL_TEMPLATE_NAME As String = "HorizontalTemplate"
    Public Const ELEMENT_VERTICAL_TEMPLATE_NAME As String = "VerticalTemplate"
    Public Const ELEMENT_GRIDSPLITTER_BACKGROUND As String = "GridSplitterBackground"
 
    Private _elementHorizontalGridSplitterButton As ToggleButton
    Private _elementVerticalGridSplitterButton As ToggleButton
    Private _elementGridSplitterBackground As Rectangle
 
#End Region
 
#Region "Dependency Properties"
 
    ''' <summary>
    ''' Gets or sets a value that indicates the CollapseMode.
    ''' </summary>
    Public Property CollapseMode() As GridSplitterCollapseMode
        Get
            Return CType(GetValue(CollapseModeProperty), GridSplitterCollapseMode)
        End Get
        Set(ByVal value As GridSplitterCollapseMode)
            SetValue(CollapseModeProperty, value)
        End Set
    End Property
    ''' <summary>
    ''' Identifies the CollapseMode dependency property
    ''' </summary>
    Public Shared ReadOnly CollapseModeProperty As DependencyProperty = DependencyProperty.Register("CollapseMode", GetType(GridSplitterCollapseMode), GetType(_3GRCGridSplitterAdvanced), New PropertyMetadata(GridSplitterCollapseMode.None, New PropertyChangedCallback(AddressOf OnCollapseModePropertyChanged)))
 
    ''' <summary>
    ''' Gets or sets the style that customizes the appearance of the horizontal handle 
    ''' that is used to expand and collapse the _3GRCGridSplitterAdvanced.
    ''' </summary>
    Public Property HorizontalHandleStyle() As Style
        Get
            Return DirectCast(GetValue(HorizontalHandleStyleProperty), Style)
        End Get
        Set(ByVal value As Style)
            SetValue(HorizontalHandleStyleProperty, value)
        End Set
    End Property
    ''' <summary>
    ''' Identifies the HorizontalHandleStyle dependency property
    ''' </summary>
    Public Shared ReadOnly HorizontalHandleStyleProperty As DependencyProperty = DependencyProperty.Register("HorizontalHandleStyle", GetType(Style), GetType(_3GRCGridSplitterAdvanced), Nothing)
 
    '''<summary>
    ''' Gets or sets the style that customizes the appearance of the vertical handle 
    ''' that is used to expand and collapse the _3GRCGridSplitterAdvanced.
    ''' </summary>
    Public Property VerticalHandleStyle() As Style
        Get
            Return DirectCast(GetValue(VerticalHandleStyleProperty), Style)
        End Get
        Set(ByVal value As Style)
            SetValue(VerticalHandleStyleProperty, value)
        End Set
    End Property
    ''' <summary>
    ''' Identifies the VerticalHandleStyle dependency property
    ''' </summary>
    Public Shared ReadOnly VerticalHandleStyleProperty As DependencyProperty = DependencyProperty.Register("VerticalHandleStyle", GetType(Style), GetType(_3GRCGridSplitterAdvanced), Nothing)
 
    ''' <summary>
    ''' Gets or sets a value that indicates if the collapse and
    ''' expanding actions should be animated.
    ''' </summary>
    Public Property IsAnimated() As Boolean
        Get
            Return CBool(GetValue(IsAnimatedProperty))
        End Get
        Set(ByVal value As Boolean)
            SetValue(IsAnimatedProperty, value)
        End Set
    End Property
    ''' <summary>
    ''' Identifies the VerticalHandleStyle dependency property
    ''' </summary>
    Public Shared ReadOnly IsAnimatedProperty As DependencyProperty = DependencyProperty.Register("IsAnimated", GetType(Boolean), GetType(_3GRCGridSplitterAdvanced), Nothing)
 
    ''' <summary>
    ''' Gets or sets a value that indicates if the target column is 
    ''' currently collapsed.
    ''' </summary>
    Public Property IsCollapsed() As Boolean
        Get
            Return CBool(GetValue(IsCollapsedProperty))
        End Get
        Set(ByVal value As Boolean)
            SetValue(IsCollapsedProperty, value)
        End Set
    End Property
    ''' <summary>
    ''' Identifies the IsCollapsed dependency property
    ''' </summary>
    Public Shared ReadOnly IsCollapsedProperty As DependencyProperty = DependencyProperty.Register("IsCollapsed", GetType(Boolean), GetType(_3GRCGridSplitterAdvanced), New PropertyMetadata(New PropertyChangedCallback(AddressOf OnIsCollapsedPropertyChanged)))
 
    ''' <summary>
    ''' The IsCollapsed property porperty changed handler.
    ''' </summary>
    ''' <param name="d">_3GRCGridSplitterAdvanced that changed IsCollapsed.</param>
    ''' <param name="e">An instance of DependencyPropertyChangedEventArgs.</param>
    Private Shared Sub OnIsCollapsedPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim s As _3GRCGridSplitterAdvanced = TryCast(d, _3GRCGridSplitterAdvanced)
 
        Dim value As Boolean = CBool(e.NewValue)
        s.OnIsCollapsedChanged(value)
    End Sub
 
    ''' <summary>
    ''' The CollapseModeProperty property changed handler.
    ''' </summary>
    ''' <param name="d">_3GRCGridSplitterAdvanced that changed IsCollapsed.</param>
    ''' <param name="e">An instance of DependencyPropertyChangedEventArgs.</param>
    Private Shared Sub OnCollapseModePropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim s As _3GRCGridSplitterAdvanced = TryCast(d, _3GRCGridSplitterAdvanced)
 
        Dim value As GridSplitterCollapseMode = CType(e.NewValue, GridSplitterCollapseMode)
        s.OnCollapseModeChanged(value)
    End Sub
 
#End Region
 
#Region "Local Members"
 
    Private _gridCollapseDirection As GridCollapseDirection = GridCollapseDirection.Auto
    Private _savedGridLength As GridLength
    Private _savedActualValue As Double
    Private _animationTimeMillis As Double = 200
 
#End Region
 
#Region "Control Instantiation"
 
    ''' <summary>
    ''' Initializes a new instance of the _3GRCGridSplitterAdvanced class,
    ''' which inherits from System.Windows.Controls._3GRCGridSplitterAdvanced.
    ''' </summary>
    Public Sub New()
        MyBase.New()
        ' Set default values
        DefaultStyleKey = GetType(_3GRCGridSplitterAdvanced)
 
        CollapseMode = GridSplitterCollapseMode.None
        IsAnimated = True
 
        AddHandler Me.LayoutUpdated, AddressOf _3GRCGridSplitterAdvanced_LayoutUpdated
    End Sub
 
    Private Sub _3GRCGridSplitterAdvanced_LayoutUpdated(ByVal sender As Object, ByVal e As System.EventArgs)
        _gridCollapseDirection = GetCollapseDirection()
    End Sub
 
    ''' <summary>
    ''' This method is called when the tempalte should be applied to the control.
    ''' </summary>
    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
 
        _elementHorizontalGridSplitterButton = TryCast(GetTemplateChild(ELEMENT_HORIZONTAL_HANDLE_NAME), ToggleButton)
        _elementVerticalGridSplitterButton = TryCast(GetTemplateChild(ELEMENT_VERTICAL_HANDLE_NAME), ToggleButton)
        _elementGridSplitterBackground = TryCast(GetTemplateChild(ELEMENT_GRIDSPLITTER_BACKGROUND), Rectangle)
 
        ' Wire up the Checked and Unchecked events of the HorizontalGridSplitterHandle.
        If _elementHorizontalGridSplitterButton IsNot Nothing Then
            AddHandler _elementHorizontalGridSplitterButton.Checked, AddressOf GridSplitterButton_Checked
            AddHandler _elementHorizontalGridSplitterButton.Unchecked, AddressOf GridSplitterButton_Unchecked
        End If
 
        ' Wire up the Checked and Unchecked events of the VerticalGridSplitterHandle.
        If _elementVerticalGridSplitterButton IsNot Nothing Then
            AddHandler _elementVerticalGridSplitterButton.Checked, AddressOf GridSplitterButton_Checked
            AddHandler _elementVerticalGridSplitterButton.Unchecked, AddressOf GridSplitterButton_Unchecked
        End If
 
        ' Set default direction since we don't have all the components layed out yet.
        _gridCollapseDirection = GridCollapseDirection.Auto
 
        ' Directely call these events so design-time view updates appropriately
        OnCollapseModeChanged(CollapseMode)
        OnIsCollapsedChanged(IsCollapsed)
    End Sub
 
#End Region
 
#Region "Protected Members"
 
    ''' <summary>
    ''' Handles the property change event of the IsCollapsed property.
    ''' </summary>
    ''' <param name="isCollapsed">The new value for the IsCollapsed property.</param>
    Protected Overridable Sub OnIsCollapsedChanged(ByVal isCollapsed As Boolean)
        ' Determine if we are dealing with a vertical or horizontal splitter.
        If _gridCollapseDirection = GridCollapseDirection.Rows Then
            If _elementHorizontalGridSplitterButton IsNot Nothing Then
                ' Sets the target ToggleButton's IsChecked property equal
                ' to the provided isCollapsed property.
                _elementHorizontalGridSplitterButton.IsChecked = isCollapsed
            End If
        Else
            If _elementVerticalGridSplitterButton IsNot Nothing Then
                ' Sets the target ToggleButton's IsChecked property equal
                ' to the provided isCollapsed property.
                _elementVerticalGridSplitterButton.IsChecked = isCollapsed
            End If
        End If
    End Sub
 
    ''' <summary>
    ''' Handles the property change event of the CollapseMode property.
    ''' </summary>
    ''' <param name="collapseMode">The new value for the CollapseMode property.</param>
    Protected Overridable Sub OnCollapseModeChanged(ByVal collapseMode As GridSplitterCollapseMode)
        ' Hide the handles if the CollapseMode is set to None.
        If collapseMode = GridSplitterCollapseMode.None Then
            If _elementHorizontalGridSplitterButton IsNot Nothing Then
                _elementHorizontalGridSplitterButton.Visibility = Visibility.Collapsed
            End If
            If _elementVerticalGridSplitterButton IsNot Nothing Then
                _elementVerticalGridSplitterButton.Visibility = Visibility.Collapsed
            End If
        Else
            ' Ensure the handles are Visible.
            If _elementHorizontalGridSplitterButton IsNot Nothing Then
                _elementHorizontalGridSplitterButton.Visibility = Visibility.Visible
            End If
            If _elementVerticalGridSplitterButton IsNot Nothing Then
                _elementVerticalGridSplitterButton.Visibility = Visibility.Visible
            End If
 
            'TODO:  Add in error handling if current template does not include an existing ScaleTransform.
 
            ' Rotate the direction that the handle is facing depending on the CollapseMode.
            If collapseMode = GridSplitterCollapseMode.Previous Then
                If _elementHorizontalGridSplitterButton IsNot Nothing Then
                    _elementHorizontalGridSplitterButton.RenderTransform.SetValue(ScaleTransform.ScaleYProperty, -1.0)
                End If
                If _elementVerticalGridSplitterButton IsNot Nothing Then
                    _elementVerticalGridSplitterButton.RenderTransform.SetValue(ScaleTransform.ScaleXProperty, -1.0)
                End If
            ElseIf collapseMode = GridSplitterCollapseMode.[Next] Then
                If _elementHorizontalGridSplitterButton IsNot Nothing Then
                    _elementHorizontalGridSplitterButton.RenderTransform.SetValue(ScaleTransform.ScaleYProperty, 1.0)
                End If
                If _elementVerticalGridSplitterButton IsNot Nothing Then
                    _elementVerticalGridSplitterButton.RenderTransform.SetValue(ScaleTransform.ScaleXProperty, 1.0)
                End If
 
            End If
        End If
 
    End Sub
 
#End Region
 
#Region "Collapse and Expand Methods"
 
    ''' <summary>
    ''' Collapses the target ColumnDefinition or RowDefinition.
    ''' </summary>
    Private Sub Collapse()
        Dim parentGrid As Grid = TryCast(MyBase.Parent, Grid)
        Dim splitterIndex As Integer = Integer.MinValue
 
        If _gridCollapseDirection = GridCollapseDirection.Rows Then
            ' Get the index of the row containing the splitter
            splitterIndex = CInt(MyBase.GetValue(Grid.RowProperty))
 
            ' Determing the curent CollapseMode
            If Me.CollapseMode = GridSplitterCollapseMode.[Next] Then
                ' Save the next rows Height information
                _savedGridLength = parentGrid.RowDefinitions(splitterIndex + 1).Height
                _savedActualValue = parentGrid.RowDefinitions(splitterIndex + 1).ActualHeight
 
                ' Collapse the next row
                If IsAnimated Then
                    AnimateCollapse(parentGrid.RowDefinitions(splitterIndex + 1))
                Else
                    parentGrid.RowDefinitions(splitterIndex + 1).SetValue(RowDefinition.HeightProperty, New GridLength(0))
                End If
            Else
                ' Save the previous row's Height information
                _savedGridLength = parentGrid.RowDefinitions(splitterIndex - 1).Height
                _savedActualValue = parentGrid.RowDefinitions(splitterIndex - 1).ActualHeight
 
                ' Collapse the previous row
                If IsAnimated Then
                    AnimateCollapse(parentGrid.RowDefinitions(splitterIndex - 1))
                Else
                    parentGrid.RowDefinitions(splitterIndex - 1).SetValue(RowDefinition.HeightProperty, New GridLength(0))
                End If
            End If
        Else
            ' Get the index of the column containing the splitter
            splitterIndex = CInt(MyBase.GetValue(Grid.ColumnProperty))
 
            ' Determing the curent CollapseMode
            If Me.CollapseMode = GridSplitterCollapseMode.[Next] Then
                ' Save the next column's Width information
                _savedGridLength = parentGrid.ColumnDefinitions(splitterIndex + 1).Width
                _savedActualValue = parentGrid.ColumnDefinitions(splitterIndex + 1).ActualWidth
 
                ' Collapse the next column
                If IsAnimated Then
                    AnimateCollapse(parentGrid.ColumnDefinitions(splitterIndex + 1))
                Else
                    parentGrid.ColumnDefinitions(splitterIndex + 1).SetValue(ColumnDefinition.WidthProperty, New GridLength(0))
                End If
            Else
                ' Save the previous column's Width information
                _savedGridLength = parentGrid.ColumnDefinitions(splitterIndex - 1).Width
                _savedActualValue = parentGrid.ColumnDefinitions(splitterIndex - 1).ActualWidth
 
                ' Collapse the previous column
                If IsAnimated Then
                    AnimateCollapse(parentGrid.ColumnDefinitions(splitterIndex - 1))
                Else
                    parentGrid.ColumnDefinitions(splitterIndex - 1).SetValue(ColumnDefinition.WidthProperty, New GridLength(0))
                End If
            End If
        End If
 
    End Sub
 
    ''' <summary>
    ''' Expands the target ColumnDefinition or RowDefinition.
    ''' </summary>
    Private Sub Expand()
        Dim parentGrid As Grid = TryCast(MyBase.Parent, Grid)
        Dim splitterIndex As Integer = Integer.MinValue
 
        If _gridCollapseDirection = GridCollapseDirection.Rows Then
            ' Get the index of the row containing the splitter
            splitterIndex = CInt(Me.GetValue(Grid.RowProperty))
 
            ' Determine the curent CollapseMode
            If Me.CollapseMode = GridSplitterCollapseMode.[Next] Then
                ' Expand the next row
                If IsAnimated Then
                    AnimateExpand(parentGrid.RowDefinitions(splitterIndex + 1))
                Else
                    parentGrid.RowDefinitions(splitterIndex + 1).SetValue(RowDefinition.HeightProperty, _savedGridLength)
                End If
            Else
                ' Expand the previous row
                If IsAnimated Then
                    AnimateExpand(parentGrid.RowDefinitions(splitterIndex - 1))
                Else
                    parentGrid.RowDefinitions(splitterIndex - 1).SetValue(RowDefinition.HeightProperty, _savedGridLength)
                End If
            End If
        Else
            ' Get the index of the column containing the splitter
            splitterIndex = CInt(Me.GetValue(Grid.ColumnProperty))
 
            ' Determine the curent CollapseMode
            If Me.CollapseMode = GridSplitterCollapseMode.[Next] Then
                ' Expand the next column
                If IsAnimated Then
                    AnimateExpand(parentGrid.ColumnDefinitions(splitterIndex + 1))
                Else
                    parentGrid.ColumnDefinitions(splitterIndex + 1).SetValue(ColumnDefinition.WidthProperty, _savedGridLength)
                End If
            Else
                ' Expand the previous column
                If IsAnimated Then
                    AnimateExpand(parentGrid.ColumnDefinitions(splitterIndex - 1))
                Else
                    parentGrid.ColumnDefinitions(splitterIndex - 1).SetValue(ColumnDefinition.WidthProperty, _savedGridLength)
                End If
            End If
        End If
    End Sub
 
    ''' <summary>
    ''' Determine the collapse direction based on the horizontal and vertical alignments
    ''' </summary>
    Private Function GetCollapseDirection() As GridCollapseDirection
        If MyBase.HorizontalAlignment <> HorizontalAlignment.Stretch Then
            Return GridCollapseDirection.Columns
        End If
        If (MyBase.VerticalAlignment = VerticalAlignment.Stretch) AndAlso (MyBase.ActualWidth <= MyBase.ActualHeight) Then
            Return GridCollapseDirection.Columns
        End If
        Return GridCollapseDirection.Rows
    End Function
 
#End Region
 
#Region "Event Handlers and Throwers"
 
    ' Define Collapsed and Expanded evenets
    Public Event Collapsed As EventHandler(Of EventArgs)
    Public Event Expanded As EventHandler(Of EventArgs)
 
    ''' <summary>
    ''' Raises the Collapsed event.
    ''' </summary>
    ''' <param name="e">Contains event arguments.</param>
    Protected Overridable Sub OnCollapsed(ByVal e As EventArgs)
        ' Dim handler As EventHandler(Of EventArgs) = Me.Collapsed
        RaiseEvent Collapsed(Me, e)
    End Sub
 
    ''' <summary>
    ''' Raises the Expanded event.
    ''' </summary>
    ''' <param name="e">Contains event arguments.</param>
    Protected Overridable Sub OnExpanded(ByVal e As EventArgs)
        ' Dim handler As EventHandler(Of EventArgs) = Me.Expanded
        RaiseEvent Expanded(Me, e)
    End Sub
 
    ''' <summary>
    ''' Handles the Checked event of either the Vertical or Horizontal
    ''' GridSplitterHandle ToggleButton.
    ''' </summary>
    ''' <param name="sender">An instance of the ToggleButton that fired the event.</param>
    ''' <param name="e">Contains event arguments for the routed event that fired.</param>
    Private Sub GridSplitterButton_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
        If IsCollapsed <> True Then
            ' In our case, Checked = Collapsed.  Which means we want everything
            ' ready to be expanded.
            Collapse()
 
            IsCollapsed = True
 
            ' Deactivate the background so the splitter can not be dragged.
            _elementGridSplitterBackground.IsHitTestVisible = False
            '_elementGridSplitterBackground.Opacity = 0.5;
 
            ' Raise the Collapsed event.
            OnCollapsed(EventArgs.Empty)
        End If
    End Sub
 
    ''' <summary>
    ''' Handles the Unchecked event of either the Vertical or Horizontal
    ''' GridSplitterHandle ToggleButton.
    ''' </summary>
    ''' <param name="sender">An instance of the ToggleButton that fired the event.</param>
    ''' <param name="e">Contains event arguments for the routed event that fired.</param>
    Private Sub GridSplitterButton_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
        If IsCollapsed <> False Then
            ' In our case, Unchecked = Expanded.  Which means we want everything
            ' ready to be collapsed.
            Expand()
 
            IsCollapsed = False
 
            ' Activate the background so the splitter can be dragged again.
            _elementGridSplitterBackground.IsHitTestVisible = True
            '_elementGridSplitterBackground.Opacity = 1;
 
            ' Raise the Expanded event.
            OnExpanded(EventArgs.Empty)
        End If
    End Sub
 
#End Region
 
#Region "Collapse and Expand Animations"
 
#Region "Property for animating rows"
 
    Private AnimatingRow As RowDefinition
 
    Private Shared ReadOnly RowHeightAnimationProperty As DependencyProperty = DependencyProperty.Register("RowHeightAnimation", GetType(Double), GetType(_3GRCGridSplitterAdvanced), New PropertyMetadata(New PropertyChangedCallback(AddressOf RowHeightAnimationChanged)))
    Private Property RowHeightAnimation() As Double
        Get
            Return CDbl(GetValue(RowHeightAnimationProperty))
        End Get
        Set(ByVal value As Double)
            SetValue(RowHeightAnimationProperty, value)
        End Set
    End Property
 
    Private Shared Sub RowHeightAnimationChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        TryCast(d, _3GRCGridSplitterAdvanced).AnimatingRow.Height = New GridLength(CDbl(e.NewValue))
    End Sub
 
#End Region
 
#Region "Property for animating columns"
 
    Private AnimatingColumn As ColumnDefinition
 
    Private Shared ReadOnly ColWidthAnimationProperty As DependencyProperty = DependencyProperty.Register("ColWidthAnimation", GetType(Double), GetType(_3GRCGridSplitterAdvanced), New PropertyMetadata(New PropertyChangedCallback(AddressOf ColWidthAnimationChanged)))
    Private Property ColWidthAnimation() As Double
        Get
            Return CDbl(GetValue(ColWidthAnimationProperty))
        End Get
        Set(ByVal value As Double)
            SetValue(ColWidthAnimationProperty, value)
        End Set
    End Property
 
    Private Shared Sub ColWidthAnimationChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        TryCast(d, _3GRCGridSplitterAdvanced).AnimatingColumn.Width = New GridLength(CDbl(e.NewValue))
    End Sub
 
#End Region
 
    ''' <summary>
    ''' Uses DoubleAnimation and a StoryBoard to animated the collapsing
    ''' of the specificed ColumnDefinition or RowDefinition.
    ''' </summary>
    ''' <param name="definition">The RowDefinition or ColumnDefintition that will be collapsed.</param>
    Private Sub AnimateCollapse(ByVal definition As Object)
        Dim currentValue As Double
 
        ' Setup the animation and StoryBoard
        Dim gridLengthAnimation As New DoubleAnimation()
        gridLengthAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(_animationTimeMillis))
 
        Dim sb As New Storyboard()
 
        ' Add the animation to the StoryBoard
        sb.Children.Add(gridLengthAnimation)
 
        If _gridCollapseDirection = GridCollapseDirection.Rows Then
            ' Specify the target RowDefinition and property (Height) that will be altered by the animation.
            Me.AnimatingRow = DirectCast(definition, RowDefinition)
            Storyboard.SetTarget(gridLengthAnimation, Me)
            Storyboard.SetTargetProperty(gridLengthAnimation, New PropertyPath("RowHeightAnimation"))
 
            currentValue = AnimatingRow.ActualHeight
        Else
            ' Specify the target ColumnDefinition and property (Width) that will be altered by the animation.
            Me.AnimatingColumn = DirectCast(definition, ColumnDefinition)
            Storyboard.SetTarget(gridLengthAnimation, Me)
            Storyboard.SetTargetProperty(gridLengthAnimation, New PropertyPath("ColWidthAnimation"))
 
            currentValue = AnimatingColumn.ActualWidth
        End If
 
        gridLengthAnimation.From = currentValue
        gridLengthAnimation.[To] = 0
 
        ' Start the StoryBoard.
        sb.Begin()
    End Sub
 
    ''' <summary>
    ''' Uses DoubleAnimation and a StoryBoard to animate the expansion
    ''' of the specificed ColumnDefinition or RowDefinition.
    ''' </summary>
    ''' <param name="definition">The RowDefinition or ColumnDefintition that will be expanded.</param>
    Private Sub AnimateExpand(ByVal definition As Object)
        Dim currentValue As Double
 
        ' Setup the animation and StoryBoard
        Dim gridLengthAnimation As New DoubleAnimation()
        gridLengthAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(_animationTimeMillis))
 
        Dim sb As New Storyboard()
 
        ' Add the animation to the StoryBoard
        sb.Children.Add(gridLengthAnimation)
 
        If _gridCollapseDirection = GridCollapseDirection.Rows Then
            ' Specify the target RowDefinition and property (Height) that will be altered by the animation.
            Me.AnimatingRow = DirectCast(definition, RowDefinition)
            Storyboard.SetTarget(gridLengthAnimation, Me)
            Storyboard.SetTargetProperty(gridLengthAnimation, New PropertyPath("RowHeightAnimation"))
 
            currentValue = AnimatingRow.ActualHeight
        Else
            ' Specify the target ColumnDefinition and property (Width) that will be altered by the animation.
            Me.AnimatingColumn = DirectCast(definition, ColumnDefinition)
            Storyboard.SetTarget(gridLengthAnimation, Me)
            Storyboard.SetTargetProperty(gridLengthAnimation, New PropertyPath("ColWidthAnimation"))
 
            currentValue = AnimatingColumn.ActualWidth
        End If
        gridLengthAnimation.From = currentValue
        gridLengthAnimation.[To] = _savedActualValue
 
        ' Start the StoryBoard.
        sb.Begin()
    End Sub
 
#End Region
 
    ''' <summary>
    ''' An enumeration that specifies the direction the _3GRCGridSplitterAdvanced will
    ''' be collapased (Rows or Columns).
    ''' </summary>
    Friend Enum GridCollapseDirection
        Auto
        Columns
        Rows
    End Enum
 
 
End Class