Esempio n. 1
0
        /// <summary>
        /// Get a selected checkbox items
        /// </summary>
        private static Node GetNodeByName(ErdDiagramModel erd, string name)
        {
            try
            {
                for (int i = 0; i < erd.Nodes.Count; i++)
                {
                    // Get a all list items from listbox

                    Node currentNode = erd.Nodes[i] as Node;
                    // find a ContentPresenter of that list item.. [Call FindVisualChild Method]
                    ContentPresenter ContentPresenterObj = WpfUIUtilities.FindVisualChild <ContentPresenter>(currentNode);

                    // call FindName on the DataTemplate of that ContentPresenter
                    DataTemplate DataTemplateObj = ContentPresenterObj.ContentTemplate;
                    Label        Chk             = (Label)DataTemplateObj.FindName("lbl", ContentPresenterObj);
                    string       content         = Chk.Content as string;
                    if (content == name)
                    {
                        return(currentNode);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
        private static void OnModelSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ErdDiagramModel erd = d as ErdDiagramModel;

            string node_source       = erd.NodeSource;
            string connector_source  = erd.ConnectorSource;
            var    newElement        = e.NewValue;
            var    type              = newElement.GetType();
            var    nodesproperty     = type.GetProperty(node_source);
            var    connectorproperty = type.GetProperty(connector_source);

            if (nodesproperty == null || connectorproperty == null)
            {
                return;
            }

            var nodes      = nodesproperty.GetValue(newElement) as IList;
            var connectors = connectorproperty.GetValue(newElement) as IList;

            if (!(nodes is IList) || !(connectors is IList))
            {
                return;
            }
            int i = 1;

            foreach (var node in nodes)
            {
                Node newnode = new Node();
                newnode.OffsetX = 300 * i;
                i++;
                newnode.OffsetY         = 10 * i;
                newnode.ContentTemplate = erd.ItemTemplate;
                newnode.Content         = node;
                erd.Nodes.Add(newnode);
            }

            foreach (var connector in connectors)
            {
                ErdLineConnector lc = new ErdLineConnector();
                lc.Content     = connector;
                lc.DataContext = connector;
                lc.Style       = erd.ConnectorStyle;
                lc.ApplyTemplate();



                erd.Connections.Add(lc);
            }
        }
Esempio n. 3
0
        private void ErdDiagramControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            ErdDiagramModel model = this.Model as ErdDiagramModel;

            foreach (Node n in model.Nodes)
            {
                ContentPresenter ContentPresenterObj = WpfUIUtilities.FindVisualChild <ContentPresenter>(n);

                // call FindName on the DataTemplate of that ContentPresenter
                DataTemplate DataTemplateObj = ContentPresenterObj.ContentTemplate;

                // Label Chk = (Label)DataTemplateObj.FindName("lbl", ContentPresenterObj);
                Header header = (Header)WpfUIUtilities.FindVisualChild <Header>(ContentPresenterObj);

                /* Panel pnl = n.ContentTemplate.LoadContent() as Panel;
                 * if (pnl == null) throw new Exception("The first element of template must be panel");
                 * Header header = pnl.Children[0] as Header;*/
                if (header == null)
                {
                    throw new Exception("The first element of template must be header");
                }
                string content = header.ItemName;


                foreach (var ee in model.Connections)
                {
                    if (!(ee is ErdLineConnector))
                    {
                        continue;
                    }
                    ErdLineConnector er = ee as ErdLineConnector;
                    if (er.HeadNodeName == content)
                    {
                        er.HeadNode = n;
                    }
                    if (er.TailNodeName == content)
                    {
                        er.TailNode = n;
                    }
                    er.ApplyTemplate();
                }
            }
        }