For console Application, when I execute window.Show(), my WPF Window is hang. But When running in App.xaml (Window Application), it is OK.
I use AggregateCatalog to initialize my objects, instead of using codes below.
var application = new System.Windows.Application();
application.Run(new MyWindow());
For AggregateCatalog:
private static AggregateCatalog catalog;
private static CompositionContainer container;
private static IEnumerable<IModuleController> moduleControllers;
private static void RunApplication()
{
catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewModel).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);
moduleControllers = container.GetExportedValues<IModuleController>();
foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); }
foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); }
}
Is there limitation if I run it in console application using the same RunApplication()?