Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf resize complete

Tags:

.net

wpf

resize

So I need to procedurally generate a background image for a grid, it only takes .1sec.

So I can wire into the SizeChanged event, but then when you resize the chart, it goes and fires the event maybe 30 times a second, so the resize event lags out signifigantly.

Does anybody know a good way to wire into the resize event and test weather the use is done resizing, I tried simply checking for the mouse up/down state, but when the resize event fires the mouse is pretty much always down.

like image 450
Joel Barsotti Avatar asked Jan 12 '10 04:01

Joel Barsotti


1 Answers

On resize, you could start a short lived timer (say 100 mSec), on each resize reset that timer to prevent it from elapsing. When the last resize happens, the timer will elapse, and you can draw your background image then.

Example:

Timer resizeTimer = new Timer(100) { Enabled = false };

public Window1()
{
    InitializeComponent();
    resizeTimer.Elapsed += new ElapsedEventHandler(ResizingDone);
}

void ResizingDone(object sender, ElapsedEventArgs e)
{
    resizeTimer.Stop();
    GenerateImage();
}

private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
    resizeTimer.Stop();
    resizeTimer.Start();
}
like image 76
Aviad P. Avatar answered Sep 22 '22 06:09

Aviad P.