How to catch the ending resize window?

后端 未结 5 657
[愿得一人]
[愿得一人] 2020-12-08 05:42

I need catch the event endresize in WPF.

5条回答
  •  温柔的废话
    2020-12-08 06:01

    For UWP with Rx (System.Reactive)

                //Stop window updates
                rootFrame = new Frame
                {
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment = VerticalAlignment.Top,
                    Width = Window.Current.Bounds.Width,
                    Height = Window.Current.Bounds.Height
                };
    
                //updates after throttling
                var sizeChangedObservable = Observable.FromEventPattern(
                          handler => Window.Current.SizeChanged += handler,
                          handler => Window.Current.SizeChanged -= handler);
    
                sizeChangedObservable.Throttle(TimeSpan.FromSeconds(0.35)).ObserveOnDispatcher(CoreDispatcherPriority.Normal).Subscribe(x =>
                {
                    rootFrame.Width = x.EventArgs.Size.Width;
                    rootFrame.Height = x.EventArgs.Size.Height;
                });
    

提交回复
热议问题