I’d like the sorting of the nodes will be made on data structure hierarchical index and not depending order in sourcesnode list.
I define my TreeLayout in code :
[Code]
fLayout.Comparer = new QDComparer();
fLayout.AlternateComparer = new QDComparer();
[\code]
With QDComparer :
[code]
public class QDComparer : IComparer
{
public int Compare(TreeVertex a, TreeVertex b)
{
QD_Node aData = a.Node.Data as QD_Node;
QD_Node bData = a.Node.Data as QD_Node;
if (aData == null)
{
if (bData == null) return 0;
return 1;
}
else
{
if (bData == null) return -1;
if (aData.HasItem && bData.HasItem)
{
return Functions.HierarchicalCompare(aData.Item.HierarchicalIndex, aData.Item.HierarchicalIndex);
}
return -1; //C'est une note ou une restriction
}
}
}
[\Code]
I set a breakpoint in the Compare function, but when diagram.Layout is called I don’t reach the breakpoint …
I can’t be sure based on what you showed above, but it appears that you create and initialize a TreeLayout but never set Diagram.Layout, so that the layout knows what graph to work on and to allow the layout to be invalidated so that it is actually performed.
I just copy/pasted your code (and added a “using System.Windows.Data;”), set a breakpoint in SimpleComparer.Compare, ran my modified GoWpfDemo TLayout sample, and immediately hit the breakpoint.
The issue is that in your application you haven’t set TreeLayout.Sorting to TreeSorting.Ascending or TreeSorting.Descending. Setting it to Forwards (or Backwards) explicitly means that it doesn’t have to call Sort – it just accepts the order in which the children are given (or the reverse if Backwards).
I haven’t well understood the Sorting enumeration.
It was set to Forwards, i change for Ascending and now all is ok.
I stop in my compare.
Just a final question on this subject : Do the compare function compare only brother nodes or compare parent and child node, or different branch child ?
(because if as I suspect it compare only same branch childs, i can simplify my compare).
It ought to be called, since nothing else has changed, has it?
Except that things have changed, since the root of the tree is now different. The former root vertexes are now child vertexes.
Except for the NodeIndent, it seems as if you really aren’t using the TreeStyle.RootOnly. So it might be easiest if you don’t bother using the Alternate… properties at all, by leaving TreeLayout.TreeStyle at its default value of TreeStyle.Layered.
Then override TreeLayout.AssignTreeVertexValues to set the value(s) that you want on each vertex, when you want them to be different from the values that they inherited from their parent vertex. Presumably you’ll only need to change the TreeVertex.NodeIndent property on those vertexes that represent nodes that are the apparent root Nodes.