I have created a WPF binding it was working fine but then I realised I needed a refresh button show when I call the SetUpData function I am getting this error:
Additional information: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
C#:
public async void GetShows(string serviceDocUri)
{
await Task.Run(() => _Shows = new ObservableCollection<Show>());
await Task.Run(() => GetAllShowsWithPath("", directoryShowDoc)); //Error shows on this line
}
More C#:
public MainWindow()
{
InitializeComponent();
this.DataContext = Workspace.This;
//Awaits the list of shows
SetUpData();
}
More C#:
private async void SetUpData()
{
await Task.Run(() => _VizManager.GetShows(_TrioLocalHost));
//This is binded to my WPF combobox
Workspace.This.TrioShow = _VManager._Shows;
}
More C#:
private async Task GetAllShowsWithPath(string directoryPath, XmlDocument xmlDoc)
{
string siteRoot = "http://";
foreach (XmlNode showNode in xmlDoc.SelectNodes("//atom:feed/atom:entry[atom:category/@term='show']/atom:title", nameSpaceManager_))
{
_Shows.Add(new Show { Title = "showTitle", ShowLink = "showLink", FullPath = "fullPath" });
}
foreach (XmlNode dirNode in xmlDoc.SelectNodes("//atom:feed/atom:entry[atom:category/@term='directory' and not(atom:category/@term='show')]/atom:title", nameSpaceManager_))
{
string dir = dirNode.InnerText;
XmlDocument xmlDoc1 = new XmlDocument();
string directoryPath1 = directoryPath + "/" + dir;
string xml = "";
string page = siteRoot + "/directory/shows" + directoryPath1 + "/";
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(page))
{
response.Headers.Add("Accepts", "application/atomsvc+xml");
using (HttpContent content = response.Content)
{
string data = await content.ReadAsStringAsync();
if (data != null)
{
xml = data;
}
}
}
xmlDoc1.LoadXml(xml);
await this.GetAllShowsWithPath(directoryPath1, xmlDoc1);
}
}