Method called in WPF when window size changes?

后端 未结 2 642
梦如初夏
梦如初夏 2021-02-10 09:09

I am creating a application using WPF. I want to calculate the coordinate of the visible region of a canvas.

Which method will be called when i resize the window, so tha

2条回答
  •  我寻月下人不归
    2021-02-10 09:32

    Provide SizeChanged="Window_SizeChanged" just like below:

    
    

    Then in your Window_SizeChanged method you can have the updated sizes as follows:

            private void Window_SizeChanged (object sender, SizeChangedEventArgs e)
            {
    
            var ah = ActualHeight;
            var aw = ActualWidth;
            var h = Height;
            var w = Width;
            Console.WriteLine ("ActualHeight(updated height value): {0}, ActualWidth(updated width value): {1}, Height(before size change): {2}, Width(before size change): {3}", ah, aw, h, w);
            }
    //output:
    // ActualHeight(updated height): 744, ActualWidth(updated width): 1382, Height(before size change): 600, Width(before size change): 1200
    

提交回复
热议问题