void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ListBoxItem connectionItem = ControlTreeHelper.FindAncestorOfType <ListBoxItem>(AssociatedObject); if (connectionItem == null) { return; } Connection connectionToDelete = connectionItem.DataContext as Connection; if (connectionToDelete == null) { return; } ConnectionsDropDownPopupControl connectivityControl = ControlTreeHelper.FindAncestorOfType <ConnectionsDropDownPopupControl>(AssociatedObject); if (connectivityControl == null) { return; } connectivityControl.DeleteConnection(connectionToDelete); e.Handled = true; }
/// <summary> /// ConnectionsProperty property changed handler. /// </summary> /// <param name="d">ConnectionsDropDownPopupControl that changed its Connections.</param> /// <param name="e">Event arguments.</param> private static void OnConnectionsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ConnectionsDropDownPopupControl source = d as ConnectionsDropDownPopupControl; source.onConnectionsChanged(); }