Hello Walter.
In my application from the recent ticket Zoom to and center a specific node I’m creating a bitmap from the final diagram.
As a small recap:
We have a navigation with subsections, somewhat like this:
- Apartments
- Level 1
- Level 2
- Rooms
- Level 1
- Level 2
- Components
- Level 1
- Level 2
Every top navigation level has its own View and its own Diagram, so when I switch from Apartments to Rooms, a new Diagram is initialized.
Each 2nd level navigation does call OnNavigatedTo but remains in the same View and keeps the same Diagram. Each 2nd level navigation point also claims one background layer, one node layer and optionally one link layer (we don’t need links in the apartment section, so there is none).
When I navigate to one of the levels I’m doing a zoom to fit on its background node by setting FixedDiagramBounds to the size of this node.
When I navigate away from a level in the Components section I’m creating a bitmap of that one Level in the diagram like this:
BitmapSource floorPlanWithComponents = diagram.Panel?.MakeBitmap(
new Size(diagram.Panel.DiagramBounds.Width, diagram.Panel.DiagramBounds.Height),
96,
new Point(diagram.Panel.DiagramBounds.X, diagram.Panel.DiagramBounds.Y),
1
);
The call to the Panel.MakeBitmap
function changes the Panel.ViewportBounds
of the diagram. So, when I navigate from Level 1 to Level 2 in the Components section I’m creating a bitmap of Level 1 and then try to scale to the background node in Level 2. To calculate the scaling factor I need to use the ViewportWidth and ViewportHeight but both are incorrect now and thus my scaling is off.
In my understanding this is an error as the ViewportBounds should not be changed. As a workaround my first thought was to save the ViewportBounds and reset them after the call to MakeBitmap but since multiple other things change (like ViewportWidth, ActualSize, RenderSize, etc.) I’m unsure what to actually set to restore the Panel’s bounds to the correct value.