Closed AlmightyLks closed 1 year ago
Hello,
Normally, the DiagramCanvas component will set the Container after the first render (see https://github.com/Blazor-Diagrams/Blazor.Diagrams/blob/master/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs#L47)
The only reason it might be null is probably because you're trying to access it before it gets the boundaries from JS?
Please try using the ContainerChanged
event and see if you do get it, if you do, then you're probably just accessing it before it's available, since iirc Blazor's OnAfterRender isn't hierarchical
Yeah; I am accessing it before it fires that event
Best bet would be adding a time delay
await Task.Delay(500);
// ...
within OnAfterRender, I guess
Or use the event, that would be more "natural". But it's up to you!
Wouldnt the event also fire under several frontend resize circumstances?
Indeed! But you can only consider the first one
After overhauling a different corner of my program, I came back to see, that my Diagram's Container happens to be null, on first AfterRender
The Diagram object is initialized within the
OnInitializedAsync
, and withinOnAfterRenderAsync
I am trying to access the Diagram, that's where the Container gives me null, causing me a NRE.Do you happen to know under what circumstances a Diagram's Container is null?
Looking into the source, the Container is only ever set through https://github.com/Blazor-Diagrams/Blazor.Diagrams/blob/ef9309c310f26a4828569c26fb8ebefa0278f83b/src/Blazor.Diagrams.Core/Diagram.cs#L331-L339 and from what I recall, I didn't need to give it an explicit Container rectangle for a Diagram to be displayed