I would like to detect changes of the zoom or size of the ViewBox
so I can apply some custom logic on the controls inside of it.
Is it possible to do?
Try this code:
private void Viewbox_SizeChanged(object sender, SizeChangedEventArgs e)
{
double initialWidth = 509.0;
if (e.PreviousSize.Width > 0)
{
var factor = e.NewSize.Width / initialWidth;
this.Title = (factor * 100).ToString();
}
}
The value 509.0 is the width of my initial Window. Every time you resize the window, I calculate the % between the new width and the initial one. I suppose that you need to subscribe MouseLeftButtonUp to detect the end of each window resizing, so you can save the new width.
Is it possible for you to subscribe the SizeChanged event?
<Viewbox SizeChanged="Viewbox_SizeChanged">
</Viewbox>
And in the code-behind you simply put:
private void Viewbox_SizeChanged(object sender, SizeChangedEventArgs e)
{
}