private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { // Get the new size of the window double newWidth = e.NewSize.Width; double newHeight = e.NewSize.Height; // Do something with the new size // For example, resize the content of the window contentGrid.Width = newWidth - 50; contentGrid.Height = newHeight - 100; }
private void ScrollViewer_SizeChanged(object sender, SizeChangedEventArgs e) { // Get the new size of the scrollviewer double newWidth = e.NewSize.Width; double newHeight = e.NewSize.Height; // Check if the new size is larger than the content size if (newWidth > contentGrid.ActualWidth || newHeight > contentGrid.ActualHeight) { // If it is, resize the content grid to fit the new scrollviewer size contentGrid.Width = newWidth; contentGrid.Height = newHeight; } }In this example, we have a scrollviewer with a content grid. When the size of the scrollviewer is changed, we want to resize the content grid to fit the new scrollviewer size, but only if the new size is larger than the content size. We use the ActualWidth and ActualHeight properties of the content grid to compare with the new size of the scrollviewer. Overall, the SizeChangedEventArgs is a useful class for handling size changes in WPF applications. It can be found in the System.Windows namespace of the WPF library.