private void RemoveCardHandler(object sender, RoutedEventArgs e) { if (Card == null) { return; } // Three cases are possible. // 1. The container is unloaded (e.g. one closes a GroupWindow). // This case is recognizable because GroupControl.IsLoaded is false. // We have to remove our listeners. // 2. The card is been moved to another group. // This is recognizable because GroupControl is null. // We have to remove our listeners. // 3. The card index changes (e.g. it's moved to top/bottom of a pile). // In this case WPF seems to unload and then reload the control at the correct position. // But in some weird cases WPF seems to call Unload WITHOUT a matching Load, // although the control ends up in the visual tree. E.g. when Moving several cards to the // top of a pile at once, with the GroupWindow open. // We can recognize this case because GroupControl.IsLoaded is true. // In this case we *keep* the listeners attached! GroupControl groupCtrl = GroupControl; if (groupCtrl != null && groupCtrl.IsLoaded) { return; } Card.PropertyChanged -= PropertyChangeHandler; Card = null; }
protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { base.OnMouseDoubleClick(e); if (_isDragging) { return; } // Double-click ends any manipulation which may be in progress. // Otherwise bugs may happen (e.g. if the default action moves the card) if (IsMouseCaptured) { ReleaseMouseCapture(); } _dragSource = DragSource.None; if (e.ChangedButton != MouseButton.Left) { return; } e.Handled = true; if (GroupControl != null) { GroupControl.ExecuteDefaultAction(Card); } }
protected void DragCardCompleted() { // Release the card and its group foreach (Card c in DraggedCards) { c.ReleaseControl(); } Card.Group.ReleaseControl(); // Remove the visual feedback var mwc = _mainWin.Content as Visual; if (mwc != null) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(mwc); foreach (CardDragAdorner overlay in OverlayElements) { layer.Remove(overlay); overlay.Dispose(); } } OverlayElements.Clear(); // Raise CardOutEvent if (_lastDragTarget != null) { _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this)); _lastDragTarget = null; } // Raise CardDroppedEvent IInputElement res = Mouse.DirectlyOver; if (res != null) { var args = new CardsEventArgs(Card, DraggedCards, CardDroppedEvent, this) { MouseOffset = _mouseOffset, FaceUp = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) }; res.RaiseEvent(args); } // Restore full opacity // FIX (jods): if the cards have been moved to another group, groupCtrl is null. // But in this case nothing has to be done opacity-wise since // the CardControls have been unloaded. GroupControl groupCtrl = GroupControl; if (groupCtrl != null) { foreach (CardControl cardCtrl in Selection.GetCardControls(groupCtrl, this)) { cardCtrl.Opacity = 1; } } DraggedCards.Clear(); }
public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl, CardControl empty) { if (IsEmpty()) yield return empty; else foreach (CardControl cardCtrl in GetCardControls(ctrl)) yield return cardCtrl; }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { e.Handled = true; if (Mouse.Captured != null) { return; // don't open during drag and drop operations } base.OnContextMenuOpening(e); GroupControl.ShowContextMenu(Card); }
public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl) { if (IsEmpty()) yield break; var groupCards = ctrl.Group.Cards; var generator = ctrl.GetItemContainerGenerator(); for (int i = 0; i < groupCards.Count; ++i) if (groupCards[i].Selected) { var container = generator.ContainerFromIndex(i); var cardCtrl = (CardControl)System.Windows.Media.VisualTreeHelper.GetChild(container, 0); yield return cardCtrl; } }
public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl) { if (IsEmpty()) yield break; ObservableCollection<Card> groupCards = ctrl.Group.Cards; ItemContainerGenerator generator = ctrl.GetItemContainerGenerator(); for (int i = 0; i < groupCards.Count; ++i) if (groupCards[i].Selected) { DependencyObject container = generator.ContainerFromIndex(i); var cardCtrl = (CardControl) VisualTreeHelper.GetChild(container, 0); yield return cardCtrl; } }
public static IEnumerable <CardControl> GetCardControls(GroupControl ctrl, CardControl empty) { if (IsEmpty()) { yield return(empty); } else { foreach (CardControl cardCtrl in GetCardControls(ctrl)) { yield return(cardCtrl); } } }
public static IEnumerable <CardControl> GetCardControls(GroupControl ctrl) { if (IsEmpty()) { yield break; } ObservableCollection <Card> groupCards = ctrl.Group.Cards; ItemContainerGenerator generator = ctrl.GetItemContainerGenerator(); for (int i = 0; i < groupCards.Count; ++i) { if (groupCards[i].Selected) { DependencyObject container = generator.ContainerFromIndex(i); var cardCtrl = (CardControl)VisualTreeHelper.GetChild(container, 0); yield return(cardCtrl); } } }
private void AnimateTurn(bool newIsUp) { TimeSpan delay = TimeSpan.Zero; GroupControl group = GroupControl; if (group != null) { delay = TimeSpan.FromMilliseconds(group.GetTurnAnimationDelay()); } var animY = new DoubleAnimation(1.1, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.HoldEnd) { BeginTime = delay }; var anim = new DoubleAnimation(0, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.HoldEnd) { BeginTime = delay }; anim.Completed += Turned; turn.BeginAnimation(ScaleTransform.ScaleYProperty, animY); turn.BeginAnimation(ScaleTransform.ScaleXProperty, anim); }