I need to access to SelectedIndex
property of a TabControl
from another thread, I tried with a Dispatcher
like this:
public ListView CurrentTab
{
get
{
ListView listView = null;
Action action = () =>
{
int currentTab = MainWindow.AppWindow.TabControl.SelectedIndex;
//Check wich tab is opened
switch (currentTab)
{
case 0:
listView = MainWindow.AppWindow.PlayingControl.Playing;
break;
case 1:
listView = MainWindow.AppWindow.AllMatchesControl.AllMatches;
break;
case 2:
listView = MainWindow.AppWindow.CustomMatchesControl.CustomMatches;
break;
}
};
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(action));
return listView;
}
}
but I get
System.InvalidOperationException
Unable to access the object by the calling thread because that object is owned by another thread properties.
I'm trying to return a list through the SelectedIndex
, what am I doing wrong?