none
ZOrder

    Question

  • 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?
    Friday, September 22, 2006 4:02 AM

Answers

  • 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);

     

     

    Sunday, September 24, 2006 10:57 PM
    Moderator

All replies

  • Hi:
    Have you try to invoke invalidate at the end of your change to force a refreshment of the diagram?

    shape.Invalidate();
    Friday, September 22, 2006 6:29 AM
  • Yes, I have tried shape.Invalidate(), and shape.Diagram.Invalidate() inside the same transaction and in another one, without success.
    Friday, September 22, 2006 6:27 PM
  • 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);

    Sunday, September 24, 2006 10:50 PM
    Moderator
  • 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);

    Sunday, September 24, 2006 10:55 PM
    Moderator
  • 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);

     

     

    Sunday, September 24, 2006 10:57 PM
    Moderator
  • Thanks for your answerS. :)

    It's been a while since the last time I took the examples. They are far better in this version.
    Thursday, September 28, 2006 5:11 AM
  • 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.
    Friday, September 29, 2006 12:47 AM
    Moderator