Thursday, 12 September 2013

Label not shown after a second Window.Show

Label not shown after a second Window.Show

I am fixing an already existing application and I am stuck on some weird
problems.
In some part of our GUI, we had operations that takes some times. So we
created a little window named Wait with a simple message Please wait... in
it. And we simply Show/Hide the window when it's needed.
But here is the problem. The second time we show the window, the Please
wait... Label in is not displayed.
The Wait.xaml:
<Window x:Class="WpfApplication1.Wait"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Wait" SizeToContent="WidthAndHeight">
<StackPanel>
<Label>Please wait...</Label>
</StackPanel>
</Window>
The Wait.xaml.cs
public partial class Wait : Window
{
public Wait()
{
InitializeComponent();
}
}
Finally I just try this in a minimal WPF application:
// The window is shown perfectly
m_WaitWindow.Show();
Thread.Sleep(5000);
m_WaitWindow.Hide();
Thread.Sleep(2000);
// The label is not shown, the window is empty
m_WaitWindow.Show();
Thread.Sleep(5000);
m_WaitWindow.Hide();
I don't know how to solve this problem, I tried a lot of things like
UpdateLayout after the Show but no effect.
More than an answer on how to solve this, I would to understand why this
is happenning ?

No comments:

Post a Comment