I need catch the event endresize in WPF.
Reactive Extensions for .NET provides some really cool capabilities for dealing with standard event patterns including being able to throttle events. I had a similar problem in dealing with size changed events and while the solution is still somewhat "hacky" I think that Reactive Extensions provides a much more elegant way of implementing it. Here is my implementation:
IObservable ObservableSizeChanges = Observable
.FromEventPattern(this, "SizeChanged")
.Select(x => x.EventArgs)
.Throttle(TimeSpan.FromMilliseconds(200));
IDisposable SizeChangedSubscription = ObservableSizeChanges
.ObserveOn(SynchronizationContext.Current)
.Subscribe(x => {
Size_Changed(x);
});
This will effectively throttle the SizeChanged
event such that your Size_Changed method (where you can execute custom code) will not be executed until 200 milliseconds (or however long you would like to wait) have passed without another SizeChanged
event being fired.
private void Size_Changed(SizeChangedEventArgs e) {
// custom code for dealing with end of size changed here
}