1

I have a console app, where I want to show wpf window:

ths = new ThreadStart(() =>
  {
     window = new wpf_lib.Container();
     System.Windows.Application app = new Application();
     app.Run(window);
  });
 th = new Thread(ths);
 th.TrySetApartmentState(ApartmentState.STA);
 th.Start();

But, how I can get access for wpf window methods and properties from any method in the console app?

Nisu
  • 185
  • 1
  • 1
  • 12

1 Answers1

0

You've two options, first and in your case easiest:

Use the System.Windows.Application.MainWindow method to get access to the Window's properties and methods.

Second: Add a property/method to the Container class that returns the Window object you want. This may or may not be possible, mostly depending on wether you've access to the source code of that class.

If you are encountering exceptions regarding thread access, use the Dispatcher of the appropriate WPF object. See this question for details.

Community
  • 1
  • 1
Steffen Winkler
  • 2,805
  • 2
  • 35
  • 58