InitialAutoScale doesn't work, whereas autoScale works

I am trying to use “InitialAutoScale” by setting it to “Uniform”, it doesn’t work.
whereas in the same place if I set “autoScale” to “Uniform” it works.

by setting autoSCale to uniform zoomIn and zoomout stops working.
I want these to work.

What code do you execute after setting Diagram.model?

I add some listeners and set my nodes and links

What do you mean by “set my nodes and links”?

I’m asking because all of the “initial…” Diagram properties define behavior that happens at the time of the “InitialLayoutCompleted” DiagramEvent. If you are causing the initialization to happen before you wanted, that would explain the behavior you are seeing. The Diagram.autoScale scaling is happening after each transaction, which is why it has an additional chance (or more) to set the Diagram.scale the way that you want.

I also tried to do it after the “InitialLayoutCompleted” event. Still, it doesn’t work!!

So you implemented an “InitialLayoutCompleted” DiagramEvent listener? That was going to be my next suggestion once I understood what you were doing initially.

So at the time of the “InitialLayoutCompleted” event, are all of the nodes and links present in the diagram at their expected positions? Can the user zoom and scroll to achieve the positioning and scaling that you wanted? (I’m assuming you have removed that setting of Diagram.autoScale.)

Do you have a screenshot of the initial viewport, and do you have one showing it the way that you want?

yes, all the nodes and links are in expected position and I am able to scroll and zoom.

The requirement is I need to show the complete diagram fitted to screen size initially.


This is how it appears, I have removed the labels of nodes.
You see some links disconnected in between ,please ignore it is because i edited image to hide labels.


This is the complete diagram which should be displayed initially.

I also tried to set initialAutoScale to Uniform in Model changes event, as mentioned earlier in InitialLayoutCompleted, and layoutcompleted as well.

Works nowhere!!

An aside: it’s easy to hide all of your text by setting the TextBlock.stroke to null.

Once you see the first screenshot, can the user zoom out and scroll to show the second screenshot? I assume that is actually what you did to make the second screenshot.

OK, so the problem really is in what you are executing between the time you set Diagram.model and the “InitialLayoutCompleted” event. Somehow you are doing something to force it to initialize prematurely. Could you please show us that code? There really shouldn’t be any such code.

for the second screenshot i just did shift+Z.

I will share the code shortly.

You don’t need to show (and I don’t really want to see) any code that you use to set up your model. Nor your templates or tool initializations, which I hope you are doing before setting the model property. What matters is only the stuff that happens after you assign the Diagram.model property.

I have a question,

What if I set “InitialAutoScale” to “uniform” everywhere I “requestUpdate”?
should that work?

Why are you calling Diagram.requestUpdate?

The Diagram.initialAutoScale property just controls some code that happens immediately before the “InitialLayoutCompleted” event happens. It’s to save programmers the bother of defining that “InitialLayoutCompleted” event handler just to zoom-to-fit or whatever they want to do for the initial view.