0

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();

       }
Community
  • 1
  • 1
  • "I am trying to send WPF usercontrol over WCF" - erm, why? – Mitch Wheat Aug 05 '13 at 02:32
  • @MitchWheat: I want to remotely host the WPF usercontrol ,which is residing on server, on the client. – user2651618 Aug 05 '13 at 02:34
  • Remotely hosting a WPF control?! This smells of an XY problem. PS Although it is possible to remotely host WPF (it is how at least one version of RDP works with WPF), it is well outside the scope of SO, and is definitely not going to be performant over WCF. – Aron Aug 05 '13 at 03:51

0 Answers0