How to create a layer?

Hi,

Is it possible to create a different layer to store temparory objects & then remove all stored temporary objects, when required?

If yes, the how?

Just create a new NodeLayer (or LinkLayer, if that’s what you need) and add it as a child of the DiagramPanel. Remember that the Diagram.Panel won’t exist until the ControlTemplate has been expanded.
myDiagram.TemplateApplied += (s, e) => {
var lay = new NodeLayer();
lay.Id = “InsertedLayer”;
myDiagram.Panel.Children.Insert(2, lay);
};
Alternatively, if you want to declare this in XAML, define all of the layers that you want in a custom ControlTemplate as the Diagram.Template.

I’m not sure what you mean by “temporary”. Are they supposed to be part of your Diagram.Model? If so, then you just add or remove the data that you want to/from that model. But if not, because the nodes are unbound (unmodeled), they should be part of the Diagram.PartsModel, which you can manipulate in the same manner.

If you set Layer.IsTemporary to true, all parts in that layer will automatically not be included in the diagram bounds, will not participate in automatic layouts, will not participate in “avoids nodes” routing, and perhaps a few other things.

Hi,

Actually I have created a link, passing through the selected node.
As soon as this selected node lost selection, then line, passing trough this selected node, should also be removed from model.
How can I search the line passing through the selected node?

I created link using the following code:

void xDiagram_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

{

if (e.AddedItems.Count == 1)

{

object selectedObject = e.AddedItems[0];

switch(selectedObject.GetType().Name)

{

case "Node":

var link = new MyLinkData();

var points = new List<Point>();

points.Add(

new Point(((Node)selectedObject).Location.X, 0));

points.Add(

new Point(((Node)selectedObject).Location.X, xDiagram.ActualHeight));

link.Points = points;

link.Category =

"GrayLinkTemplate";

link.Color =

"Red";

link.Thickness =

"1";

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).Modifiable = true;

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).AddLink(link);

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).Modifiable = false;

break;

}

}

if

(e.RemovedItems.Count == 1)

{

object deSelectedObject = e.RemovedItems[0];

switch (deSelectedObject.GetType().Name)

{

case "Node":

}

}}

Hi,

Please check my approach in reference to performance, as I am searching all links of my diagram. If any other better approach is possible, then please let me know.

I added a property ‘Label’ in ‘MyLinkData’ class.
When I create a link on node selection, then I set

link.Layer =

“TempLayer”;


When this node list selection, then I search

Diagram.LinksSource & check condition to remove from diagram:

if

(xAxisLink.Layer == “TempLayer”)


I implemented it in the following way:

void

xDiagram_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

{

if (e.AddedItems.Count == 1)

{

object selectedObject = e.AddedItems[0];

switch(selectedObject.GetType().Name)

{

case "Node":

var link = new MyLinkData();

var points = new List<Point>();

points.Add(

new Point(((Node)selectedObject).Location.X, 0));

points.Add(

new Point(((Node)selectedObject).Location.X, xDiagram.ActualHeight));

link.Points = points;

link.Category =

"LinkTemplate";

link.Color =

"Red";

link.Thickness =

"1";

link.Layer =

"TempLayer";

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).Modifiable = true;

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).AddLink(link);

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).Modifiable = false;

break;

}

}

if(e.RemovedItems.Count > 0)

{

foreach (var deSelectedObject in e.RemovedItems)

{

switch (deSelectedObject.GetType().Name)

{

case "Node":

var xAxisLinks = xDiagram.LinksSource as IEnumerable<MyLinkData>;

if (xAxisLinks != null)

{

List<MyLinkData> xAxisLinksList = xAxisLinks.ToList();

foreach (var xAxisLink in xAxisLinksList)

{

if (xAxisLink.Layer == "TempLayer")

{

xDiagram.Model.Modifiable =

true;

((

GraphLinksModel<MyNodeData, String, String, MyLinkData>)xDiagram.Model).RemoveLink(xAxisLink);

xDiagram.Model.Modifiable =

false;

}

}

}

break;

}

}

}

}

Call Diagram.Panel.FindPartsIn.

Hi,

How can I implement using Diagram.Panel.FindPartsIn?

Can you provide me a small sample using my code in previos reply?

If you search the samples, you will find an example in the LocalExpand sample.