Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm no WPF expert but I'm wondering why you would use the dispatcher object for this functionality surely you could just do this?</p> <pre><code>private void SetActiveTab(TabType type) { loaderTabs.SelectedIndex = (int)type; } </code></pre> <p>EDIT:</p> <p>Ok I fully understand now why you would use the dispatcher duh. I tried the bits on your code while processing on a seperate thread and it worked for me. </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Threading; using System.ComponentModel; namespace WpfApplication1 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { private BackgroundWorker _worker; public MainWindow() { InitializeComponent(); _worker = new BackgroundWorker(); _worker.DoWork += new DoWorkEventHandler(_worker_DoWork); _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted); } void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("Done"); } void _worker_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(5000); } private void SetActiveTab(TabType type) { loaderTabs.Dispatcher.Invoke((Action)(() =&gt; { //This is where the error happens when I try set the active tab back to tab1 loaderTabs.SelectedIndex = (int)type; })); } public void Login(string userName, string password) { try { SetActiveTab(TabType.Loader); //Processing... _worker.RunWorkerAsync(); } catch (Exception) { SetActiveTab(TabType.Login); } } enum TabType {Login, Loader}; private void Button_Click(object sender, RoutedEventArgs e) { Login("user", "password"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload