I need to open my Window.xaml
in Unit Test. I tried a simple code as follows:
[Test]
public void Test_window()
{
var mw = new MainWindow();
mw.Show();
}
The above code ends with an error.
The calling thread must be STA, because many UI components require this.
Afterwards, I tried the below code :
[Test]
public void Test_window()
{
Thread th = new Thread(new ThreadStart(delegate
{
var mw = new MainWindow();
mw.Show();
}));
th.ApartmentState = ApartmentState.STA;
th.Start();
}
In this case , the test passes successfully, but no window is shown. Since I am new to WPF, it would be appreciable if any suggestions or guidance are available here.
Thanks.
Aucun commentaire:
Enregistrer un commentaire