Allows dynamic scaling of an Avalonia Window and all of it's content.
This is the solution to this question on stackoverflow.
To use this code you have to:
-
Derive your application main
Window
fromScalableWindow
and implement the resizing events like in the provided example. (I put aPanel
in the bottom right corner of my window to be used for resizing, you'll figure it out.) -
Then implement
IViewModel
in the corresponding view model (see the example). -
Call
ScalingProvider.Register(window, viewModel);
on application startup (after Avalonia is done initializing.) -
Now you can Rescale the window as follows:
ScalingManager mainWindowManager = ScalingProvider.GetInstance<MainWindow>(); mainWindowManager.SetScaling(1.5d);
This would scale the window of type
MainWindow
to 150% of it's original size. Scaling is always in respect to the original size.