private void TimeLine_PreviewMouseDown(object sender, MouseButtonEventArgs e) { FrameworkElement element = null; try { element = ((FrameworkElement)e.OriginalSource).TemplatedParent as FrameworkElement; } catch (InvalidCastException) { return; } AllItems.ForEach(i => i.IsSelected = false); SelectedItem = null; if (element is TrackItem trackItem) { trackItem.IsSelected = true; SelectedItem = trackItem; ItemSelected?.Invoke(trackItem, new EventArgs()); } else { ItemDeselected?.Invoke(null, new EventArgs()); } }