I need catch the event endresize in WPF.
NO Timer Needed with very clean solution that have given by @Bohoo up, i just adapted his code from vb.net to c#
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// this two line have to be exactly onload
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
}
const int WM_SIZING = 0x214;
const int WM_EXITSIZEMOVE = 0x232;
private static bool WindowWasResized = false;
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_SIZING)
{
if (WindowWasResized == false)
{
// 'indicate the the user is resizing and not moving the window
WindowWasResized = true;
}
}
if (msg == WM_EXITSIZEMOVE)
{
// 'check that this is the end of resize and not move operation
if (WindowWasResized == true)
{
// your stuff to do
Console.WriteLine("End");
// 'set it back to false for the next resize/move
WindowWasResized = false;
}
}
return IntPtr.Zero;
}
}