I want to bind listbox in windows phone app 8.1. I am using following code but It raise an error :
Additional information: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).
I am using the following code
private void getResponse(IAsyncResult result)
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
if (request != null)
{
try
{
WebResponse response = request.EndGetResponse(result);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string read = streamRead.ReadToEnd();
deserializeJsonString(read);
List<lstData> list = new List<lstData>();
lstData lstObj = new lstData();
foreach (var itm in childList.AppData)
{
lstObj.app_name = Convert.ToString(itm.app_name);
lstObj.app_url = Convert.ToString(itm.app_url);
list.Add(lstObj);
}
mylistbox.ItemsSource = list;
}
catch (WebException e)
{
// Debug.WriteLine("Exception in getResponse" + e);
}
}
}
and my xaml page :
<ListBox x:Name="mylistbox" Margin="0,234,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding app_name}" FontSize="45" Margin="0,10" Width="204"></TextBlock>
<TextBlock Text="{Binding app_url}" FontSize="35" Width="246" Margin="0,10"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>