Avi*_* P. 23
在调整大小时,你可以启动一个短暂的计时器(比如100毫秒),在每次调整大小时重置该计时器以防止它流逝.当最后一次调整大小时,计时器将会过去,然后您可以绘制背景图像.
例:
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();
}
Run Code Online (Sandbox Code Playgroud)
这是干净的解决方案:
private const int WmExitSizeMove = 0x232;
private void OnLoaded(object sender, RoutedEventArgs args)
{
var helper = new WindowInteropHelper(this);
if (helper.Handle != null)
{
var source = HwndSource.FromHwnd(helper.Handle);
if (source != null)
source.AddHook(HwndMessageHook);
}
}
private IntPtr HwndMessageHook(IntPtr wnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WmExitSizeMove:
// DO SOMETHING HERE
handled = true;
break;
}
return IntPtr.Zero;
}
Run Code Online (Sandbox Code Playgroud)
祝好运!
| 归档时间: |
|
| 查看次数: |
8031 次 |
| 最近记录: |