private static void OnSelectedItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ListBox listBox = d as ListBox;
if (listBox == null)
throw new InvalidOperationException("The ListBoxExtension.SelectedItemsSource attached property can only be applied to ListBox controls.");
listBox.SelectionChanged -= new SelectionChangedEventHandler(OnListBoxSelectionChanged);
if (e.NewValue != null)
{
ListenForChanges(listBox);
}
}