I have a WPF window that changes it's size over time due to SizeToContent="WidthAndHeight". Initially the WindowStartupLocation="CenterScreen" shows the window centered correctly, and after that I recenter it with:
Private Sub Window_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
Me.Top = (SystemParameters.WorkArea.Height - e.NewSize.Height) / 2
Me.Left = (SystemParameters.WorkArea.Width - e.NewSize.Width) / 2
End Sub
But it produces a "jump" as the window is resized first and centered after.
Is there any way of doing it smoothly?
Instead of setting Me.Top and Me.Left directly you can use a TranslateTransform to animate position change.
Code source: WPF. Easiest way to move Image to (X,Y) programmatically?