Referring to link: https://stackoverflow.com/a/1699709
I am trying to send WPF usercontrol over WCF using serializer/deserializer. How can i do that. I am getting following exception when making a call on server proxy: “The calling thread must be STA, because many UI components require this.” Error in WPF?
Code Snippet:
private string userControlString;
private void OnAddCommand(object param)
{
Thread thread = new Thread(ProcessTheData);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
StringReader stringReader = new StringReader(userControlString);
XmlReader xmlReader = XmlReader.Create(stringReader);
UserDefinedControl = (UserControl)XamlReader.Load(xmlReader);
}
void ProcessTheData()
{
userControlString = service.WPFViaWCFControl();
}