I am trying to jump over some hoops at the moment while working with a WPF SizeChanged event in a window. I have some user code that I need to execute after , the user has finished resizing the window, unfortunately there is no event that I could find for this, so I created a solution using Reactive Extensions to throttle the SizeChange event:
IObservable<SizeChangedEventArgs> ObservableSizeChanges = Observable .FromEventPattern<SizeChangedEventArgs>(this, "SizeChanged") .Select(x => x.EventArgs) .Throttle(TimeSpan.FromMilliseconds(200)); IDisposable SizeChangedSubscription = ObservableSizeChanges .ObserveOn(SynchronizationContext.Current) .Subscribe(x => { Size_Changed(x); });
Basically, what this does is ensure that 200 milliseconds without SizeChanged events must pass before it invokes my custom code. This works great, but I ran into the problem that if the user drags the window handle and continues to hold the mouse button, the code will still be executed. I want to make sure that custom code cannot be executed when the mouse button is unavailable. I tried to connect to PreviewMouseLeftButtonDown , but it does not start when the window handle is clicked, only when the mouse click is inside the window frame. Is there any similar event that I can hook up for a mouse that relates to a window handle? Or can someone think of a suitable workaround for the problem that I have?
source share