When I run a ShowDialog call from within a Unit test, I'm getting a
System.Windows.Markup.XamlParseException: The current SynchronizationContext may not be used as a task scheduler.
Running from main works fine. I realize this isn't the normal use of a tester, but it's valuable to be able to pick a dialog and click a button to run it with test data, to see if the dialog works. However this bug prevents me from running it.
Is there maybe a trick to run the dialog code on the "proper" thread?
Here's the Unit testing code:
[Fact]
static public void Draw2()
{
var uiThread = new Thread(Draw20);
uiThread.SetApartmentState(ApartmentState.STA);
uiThread.Start();
// Wait for the UI thread to finish
uiThread.Join();
}
static void Draw20()
{
ModernUIApp1.MainWindow window = new MainWindow();
System.Windows.Forms.Integration
.ElementHost
.EnableModelessKeyboardInterop(window);
window.ShowDialog();
window = null;
}
Window code: >
<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName="welcome">
<mui:LinkGroup.Links>
<mui:Link DisplayName="home" Source="/Pages/Home.xaml" />
<mui:Link DisplayName="my page" Source="/Pages/BasicPage.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
<mui:LinkGroup DisplayName="settings" GroupName="settings">
<mui:LinkGroup.Links>
<mui:Link DisplayName="software" Source="/Pages/Settings.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
<mui:ModernWindow.TitleLinks>
<mui:Link DisplayName="settings" Source="/Pages/Settings.xaml" />
</mui:ModernWindow.TitleLinks>
</mui:ModernWindow>