コード例 #1
0
        /// <summary>
        /// ドラッグ終了
        /// </summary>
        private void ConnectorItem_DragCompleted(object sender, ConnectorItemDragCompletedEventArgs e)
        {
            var ctrl = e.OriginalSource as ConnectorControl;

            if (ctrl == null || draggingLinkModel_ == null)
            {
                return;
            }

            // ドラッグオーバーチェック
            Point            mousePoint           = Mouse.GetPosition(PART_Canvas_);
            ConnectorControl connectorDraggedOver = null;
            bool             isHit = CheckConnectorControlDraggedOver(mousePoint, out connectorDraggedOver);

            // イベント起動
            var position = Mouse.GetPosition(ctrl.ParentEditControl);

            RaiseEvent(new ConnectionDragCompletedEventArgs(ConnectionDragCompletedEvent, this,
                                                            ctrl.ParentNodeControl.DataContext,
                                                            draggingLinkModel_,
                                                            ctrl.DataContext,
                                                            isHit ? connectorDraggedOver.DataContext : null,
                                                            position));

            draggingLinkModel_ = null;
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        private bool CheckConnectorControlDraggedOver(Point hitPoint, out ConnectorControl connectorDraggedOver)
        {
            connectorDraggedOver = null;

            // ヒットチェック
            HitTestResult result = null;

            VisualTreeHelper.HitTest(PART_NodeList_, null, (hitTestResult) => {
                result = hitTestResult;
                return(HitTestResultBehavior.Stop);
            },
                                     new PointHitTestParameters(hitPoint));

            if (result == null || result.VisualHit == null)
            {
                // Hit test failed.
                return(false);
            }

            // ヒットしたものがConnectorの子か調べる
            var hitItem = result.VisualHit as FrameworkElement;

            if (hitItem == null)
            {
                return(false);
            }
            var connector = FindVisualParentWithType <ConnectorControl>(hitItem);

            if (connector == null)
            {
                return(false);
            }
            connectorDraggedOver = connector;

            return(true);
        }