예제 #1
0
        /// <summary>
        /// When linking nodes, adds source connector to the diagram's view model for information access.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyDiagram_ConnectionManipulationStarted(object sender, ManipulationRoutedEventArgs e)
        {
            if (e.ManipulationStatus == ManipulationStatus.Attaching)
            {
                var connector = e.Connector as BaseConnector;
                if (connector != null && connector.DataContext is ConnectorViewModel)
                {
                    var viewModel = connector.DataContext as ConnectorViewModel;

                    if (viewModel.CanConnect())
                    {
                        sourceConnector = connector;
                        diagramViewModel.SourceConnector = viewModel;

                        return;
                    }
                    else
                    {
                        viewModel.IsConnected = false;
                    }
                }
            }

            sourceConnector = null;
            diagramViewModel.SourceConnector = null;
            diagramViewModel.TargetConnector = null;

            e.Handled = true;
        }
예제 #2
0
        /// <summary>
        /// Creates connector text based on connectors
        /// </summary>
        /// <param name="connector">Connector instance</param>
        public void LoadConnectorText(BaseConnector connector)
        {
            const int    leftOffset = 8;
            const double topOffset  = 8.5d;

            const double leftOffsetFlow = 9.5d;
            const double topOffsetFlow  = 5.5d;

            var canvas     = WPFVisualTreeHelper.FindChild <Canvas>(this);
            var connectors = WPFVisualTreeHelper.FindChildren <RadDiagramConnector>(this);

            foreach (var item in connectors.OfType <BaseConnector>())
            {
                if (item != connector)
                {
                    continue;
                }

                var text = new TextBlock {
                    Text = item.Text, Foreground = Brushes.White
                };
                canvas.Children.Add(text);

                var connectorLocation = item.TranslatePoint(new Point(0, 0), this);

                if (item.ConnectorDirection == ConnectorDirection.In)
                {
                    if (item is FlowConnector)
                    {
                        text.SetLocation(connectorLocation.X + leftOffsetFlow, connectorLocation.Y - topOffsetFlow);
                    }
                    else
                    {
                        text.SetLocation(connectorLocation.X + leftOffset, connectorLocation.Y - topOffset);
                    }
                }
                else
                {
                    if (item is FlowConnector)
                    {
                        outPinTexts[text] = new Point(connectorLocation.X, connectorLocation.Y - topOffsetFlow);
                    }
                    else
                    {
                        outPinTexts[text] = new Point(connectorLocation.X, connectorLocation.Y - topOffset);
                    }

                    text.Loaded += Text_Loaded;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// When linking nodes, updates source's and target's data contexts.
        /// If linking is possible, updates target connector of diagram view model with target's view model.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyDiagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
        {
            if (sourceConnector != null && e.Connector != null && e.Connector != sourceConnector &&
                e.ManipulationStatus == ManipulationStatus.Attaching)
            {
                var sourceConnectorViewModel = sourceConnector.DataContext as ConnectorViewModel;

                var targetConnector          = e.Connector as BaseConnector;
                var targetConnectorViewModel = targetConnector.DataContext as ConnectorViewModel;

                if (targetConnectorViewModel.CanConnectTo(sourceConnectorViewModel))
                {
                    diagramViewModel.TargetConnector = targetConnectorViewModel;

                    return;
                }
            }

            (sourceConnector.DataContext as ConnectorViewModel).IsConnected = false;
            sourceConnector = null;
            diagramViewModel.SourceConnector = null;
            diagramViewModel.TargetConnector = null;
            e.Handled = true;
        }