UserControls.userGridGunler ug = new UserControls.userGridGunler();//My user control
ug.Basliklar.ItemsSource = basliklar;
ug.Saatler.ItemsSource = saha.Satirlar;
TabItem ti = new TabItem();
ti.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate
{
ti.Header = saha.SahaAdı + " (" + saha.SahaTipi + ")";
ti.Content = ug;
});
//tabSahalar is my TabControl in mainWindow
tabSahalar.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate
{
tabSahalar.Items.Add(ti);//PROBLEM IS HERE
//tabSahalar.Items.Add(new TabItem { Header = "asdasdad" });//Problem no here
});
This is my code. I want to multithreading add tabitem in tabControl. But I get "The calling thread cannot access this object because a different thread owns it." error at "PROBLEM IS HERE" place.