I’m sure this is really simple, but I just can’t see a way how to go about it.
I have a canvas in the second tab of a tab control.
The tab is first disabled until some other method is executed, then the tab is enabled and I am trying to plot the results in the canvas.
It would be nice to be able to scale and centre the plot in the canvas and for that I need to get its actual dimensions.
The problem is that when I first load the results, the tab with the canvas hasn’t been activated yet and the ActualHeight and ActualWidth of the canvas are both 0. I also make the canvas stretch in both directions, so the Width and Height are NaN. Basically I am in a bind as to getting the dimensions with which to scale the plot… Is there any way to get those values before switching to the tab?
I obviously would like to avoid a lame solution like have a button that says “click here to rescale the graph”. The use should just be able to switch to the tab and have the results there.
You would need to handle the SizeChanged event of the Canvas some way or another (Event to Command binding or directly in code behind). When this event occurs get the canvas’ ActualHeight and ActualWidth and scale your graph accordingly.