28 lines
907 B
C#
28 lines
907 B
C#
![]() |
using System.Collections.Specialized;
|
|||
|
using System.Windows.Controls;
|
|||
|
using Microsoft.Xaml.Behaviors;
|
|||
|
namespace SWS.Electrical
|
|||
|
{
|
|||
|
public class ListBoxScrollToBottomBehavior : Behavior<ListBox>
|
|||
|
{
|
|||
|
protected override void OnAttached()
|
|||
|
{
|
|||
|
base.OnAttached();
|
|||
|
((INotifyCollectionChanged)AssociatedObject.Items).CollectionChanged += OnCollectionChanged;
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnDetaching()
|
|||
|
{
|
|||
|
base.OnDetaching();
|
|||
|
((INotifyCollectionChanged)AssociatedObject.Items).CollectionChanged -= OnCollectionChanged;
|
|||
|
}
|
|||
|
|
|||
|
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|||
|
{
|
|||
|
if (AssociatedObject.HasItems)
|
|||
|
{
|
|||
|
AssociatedObject.ScrollIntoView(AssociatedObject.Items[AssociatedObject.Items.Count - 1]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|