Q: Window.SizeToContent issue My app has a Window with a TextBox in it. My Window's SizeToContent is set to WidthAndHeight. I show this window from a background thread using Dispatcher.Invoke(). The problem is that the Window doesn't size to its contents when it first appears. As soon as I change text of the TextBox, the Window shrinks to correct size.
I have tried calling the following too in Dispatcher.Invoke():


*

*Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, new Action(() => { }));

*WindowObject.InvalidateVisual();

*WindowObject.UpdateLayout();
but it doesn't affect initial window size. What do I need to do?
UPDATE: I also confirmed that Window shrinks to correct size if I assign a value to TextBox's Text property programmatically. Adding the following 3 lines after calling WindowObject.Show() in Dispatcher-invoked function sets it to correct size:
var Old = WindowObject.TXT.Text;
WindowObject.TXT.SetCurrentValue(TextBox.TextProperty, "");
WindowObjectTXT.SetCurrentValue(TextBox.TextProperty, Old);


A: I just tested this and by using either Show or ShowDialog method of Window to display the Window with the Textbox you want to open up with its adjusted intiial windows size, I could display this window with the correct size. 
I added a button with the following click handler to display the window: 
private void Button_Click(object sender, RoutedEventArgs e)
{
Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
{
var pWnd = new PopWindow();
pWnd.ShowDialog();
pWnd.InvalidateVisual();
pWnd.UpdateLayout();

}));
 }