2aeaccf30a
-Miglioramenti vari.
43 lines
1.5 KiB
VB.net
43 lines
1.5 KiB
VB.net
Imports System.Windows.Interactivity
|
|
|
|
Public Class ScrollIntoViewForListBox
|
|
Inherits Behavior(Of ListBox)
|
|
|
|
''' <summary>
|
|
''' When Beahvior is attached
|
|
''' </summary>
|
|
Protected Overrides Sub OnAttached()
|
|
MyBase.OnAttached()
|
|
AddHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' On Selection Changed
|
|
''' </summary>
|
|
''' <param name="sender"></param>
|
|
''' <param name="e"></param>
|
|
Private Sub AssociatedObject_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
|
|
If TypeOf sender Is ListBox Then
|
|
Dim listBox As ListBox = TryCast(sender, ListBox)
|
|
If listBox.SelectedItem IsNot Nothing Then
|
|
listBox.Dispatcher.BeginInvoke(DirectCast(Sub()
|
|
listBox.UpdateLayout()
|
|
If listBox.SelectedItem IsNot Nothing Then
|
|
listBox.ScrollIntoView(listBox.SelectedItem)
|
|
End If
|
|
|
|
End Sub, Action))
|
|
End If
|
|
End If
|
|
End Sub
|
|
''' <summary>
|
|
''' When behavior is detached
|
|
''' </summary>
|
|
Protected Overrides Sub OnDetaching()
|
|
MyBase.OnDetaching()
|
|
RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged
|
|
|
|
End Sub
|
|
|
|
End Class
|