1

I have to navigate to a page which belongs to the main window from a different thread. I created a separate thread to listen to command line arguments of another process. When I receive "about" from that process through IPC in the thread, I need to open about.xaml from the thread. How can I do it?

This is how I open the page from main window:

_mainFrame.Source = new System.Uri("AboutPage.xaml", UriKind.Relative); 

How can I do the same from different thread ?

Sinatr
  • 20,892
  • 15
  • 90
  • 319
Unknown
  • 73
  • 8
  • wpf? still too broad.. what have you tried or where do you stuck? – Sinatr Sep 28 '15 at 14:24
  • I think you're using `WPF` , please add the `WPF` tag and add some code – Sybren Sep 28 '15 at 14:26
  • yes WPF. _mainFrame.Source = new System.Uri("AboutPage.xaml", UriKind.Relative); This is how I open the page from mainwindow. How can I do the same from different thread. – Unknown Sep 28 '15 at 14:29
  • 1
    Do you have errors? You can search for error message to get answer within seconds. From different thread you have to *invoke* into UI thread, by using [`Invoke`](https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.invoke.aspx). This is then basically a duplicate of [this](http://stackoverflow.com/q/1284017/1997232) question. – Sinatr Sep 28 '15 at 14:47
  • thanks! answer of that question is working perfectly ! – Unknown Sep 28 '15 at 15:00

1 Answers1

2

you can use the dispatcher to send actions to the UI thread.

Dispatcher.CurrentDispatcher.Invoke(()=>
{
        _mainFrame.Source = new System.Uri("AboutPage.xaml", UriKind.Relative); 
});
Chris
  • 915
  • 8
  • 28