I have a trivially simple window:
<Window x:Class="Prestress.UI.StatusWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:Prestress.UI"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
SizeToContent="WidthAndHeight"
WindowStyle="None"
ShowInTaskbar="False"
WindowStartupLocation="CenterOwner">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Path=StatusText, Source={x:Static l:ProjectProperties.Instance}}"/>
</Grid>
</Window>
with an equally trivial code-behind:
public partial class StatusWindow : Window
{
public StatusWindow()
{
Topmost = true;
InitializeComponent();
}
}
This window is just meant to show some messages to the user while the program runs in the background. The only instance of this class is contained within the following:
public sealed class ProjectProperties : DependencyObject, INotifyPropertyChanged
{
static ProjectProperties instance = new ProjectProperties();
public static StatusWindow Status = new StatusWindow();
string statusText;
public static ProjectProperties Instance { get { return instance; } }
public string StatusText
{
get { return statusText; }
set
{
statusText = value;
EmitPropertyChanged("StatusText");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void EmitPropertyChanged(string property)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
public static void UpdateStatusWindow(string s)
{
Instance.StatusText = s;
}
public static void ShowStatusWindow()
{
Status.InitializeComponent();
Status.Show();
}
}
Where ProjectProperties is a singleton class which contains a static copy of this window.
The first message it must present is "Validating data". This is done by calling
ProjectProperties.UpdateStatusWindow("Validating data.");
ProjectProperties.ShowStatusWindow();
The result is this
However, this window is soon followed by a MessageBox which complains about an error in what the user inputted. When this MessageBox appears, the window is refreshed, showing the desired text.
This seems odd to me. As can be seen, even when blank the window has already resized itself so that the text will fit. All that's missing is to paint the text. My first attempt didn't even include the .InitializeComponent()
line when calling .ShowStatusWindow()
, but then I saw this and tried adding it, to no success. Any ideas on what's going on here?