ZOrder

I am having problems setting the ZORder manually.

...
using (Transaction t = this.Store.TransactionManager.BeginTransaction("Setting ZOrder"))
{
try
{
shape.ZOrder = shapeParent.ZOrder + 1;
t.Commit();
}
catch (Exception xException)
{
t.Rollback();
System.Diagnostics.Debug.WriteLine(xException);
}
}

The code works, but the shape doesn't change the visual arrangement in the diagram.
Is it working?

[493 byte] By [leovernazza] at [2007-12-24]
# 1
Hi:
Have you try to invoke invalidate at the end of your change to force a refreshment of the diagram?

shape.Invalidate();

PedroJ.Molina at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2
Yes, I have triedshape.Invalidate(), andshape.Diagram.Invalidate() inside the same transaction and in another one, without success.
leovernazza at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3

Setting the Z-Order by itself doesn't fix things. You have to re-order the NestedChildShapes of the diagram.

Take a look at Example.Components that you'll find by opening the VS SDK Samples Browser and look in CustomCode\NestedShapes.cs. Search on FixZOrder.

Note lines like

LinkedElementCollection<ShapeElement> allShapes = movedShape.ParentShape.NestedChildShapes;

...

allShapes.Move(i, allShapes.Count - 1);

AlanCameronWills at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4

Changing the ZOrder doesn't change the Z-Order! You need to rearrange the content of the diagram's NestedChildShapes, using the Move operation.

See the Example.Components sample that you'll find by opening the VS SDK Samples browser - it will be in somewhere like Program Files\VisualStudio 2005 SDK\2006.09\VisualStudioIntegration\Samples\DSLTools\Example.DesignerCustomizations\Example.Components

Open Dsl\CustomCode\NestedShapes.cs and search in FixZOrder.

Look particularly at lines like

LinkedElementCollection<ShapeElement> allShapes = movedShape.ParentShape.NestedChildShapes;

allShapes.Move(i, allShapes.Count - 1);

AlanCameronWills at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 5

Changing the ZOrder doesn't change the Z-Order! You need to rearrange the content of the diagram's NestedChildShapes, using the Move operation.

See the Example.Components sample that you'll find by opening the VS SDK Samples browser - it will be in somewhere like Program Files\VisualStudio 2005 SDK\2006.09\VisualStudioIntegration\Samples\DSLTools\Example.DesignerCustomizations\Example.Components

Open Dsl\CustomCode\NestedShapes.cs and search in FixZOrder.

Look particularly at lines like

LinkedElementCollection<ShapeElement> allShapes = movedShape.ParentShape.NestedChildShapes;

allShapes.Move(i, allShapes.Count - 1);

AlanCameronWills at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 6
Thanks for your answerS. :)

It's been a while since the last time I took the examples. They are far better in this version.

leovernazza at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 7
So another way to put Alan's answer is that at the current time, ZOrder is calculated rather than really stored. You cna play tricks by overriding the ZOrder proeprty and supplying your own implementation, but you cna get some other weird effects happenign if you do, so beware.
GarethJ-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified