简体   繁体   中英

WPF form should resize to show its content

When WPF window appear first time, its content seem frozen. To refresh content I need to resize form, then it will be fixed. Or I hit the TAB then find a listbox -it's not visible- and click it and viola! Form updates its content again.

What do you think? Weird huh? Thanks in advance!

在此输入图像描述

Edit:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   this.Show();

   while (!AppMain.needClose)
   {
      System.Windows.Forms.Application.DoEvents();
      DoThings();
   }
}

Resizing the window would force the internals to invalidate and re-paint. You could try invalidating the form when it's loaded to force it to do the same:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   this.Show();

   this.Invalidate();

   while (!AppMain.needClose)
   {
      System.Windows.Forms.Application.DoEvents();
      DoThings();
   }
}

Unless you're doing some sort of custom message pumping though, the standard forms message pump should do that while loop for you. You might well find that because you're intercepting the window loaded event you're stopping initialisation from completing.

Calling DoEvents is a bad code smell in my experience. If you need to do something periodically, it's better to trigger it from a timer of some sort.

当你的窗口加载它已经显示,为什么你再次调用this.show()?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM