title: System.UnauthorizedAccessException - Invalid cross-thread access
body: <p>I have very simple application and I have issues with using databinding. I have succesfully downloaded used this example : <a href="http://msdn.microsoft.com/en-us/magazine/hh852595.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/hh852595.aspx</a></p>
  
  <p>There is "next" button, which generates new person and load it into application.</p>
  
  <p>However I tried to do the same and I got the following exception : <code>System.UnauthorizedAccessException - Invalid cross-thread access</code></p>
  
  <p>I tried to do the same with this :</p>
  
  <pre><code>    public Chat()
      {
          InitializeComponent();
          bindingChat.leftText = "jooooo2";
          ContentPanel.DataContext = bindingChat;
      }   
  
      private void connect(object sender, XmppConnectedEventArgs target)
      {
          bindingChat = new BindingChat();
          bindingChat.leftText = "Connected";
          ContentPanel.DataContext = bindingChat; //this is where the exception is thrown
      }
  </code></pre>
  
  <p>Text "jooooo2" works as expected, but when connet method is called, the exception mentioned appears.</p>
  
  <p>In the example, which is working, they set up new person (after clicking a button) with this code :</p>
  
  <pre><code>    private void SetDataContext()
      {
          GeneratePerson();
          ContentPanel.DataContext = _currentPerson;
      }
  </code></pre>
  
  <p>And it works fine.</p>
  
  <hr>
  
  <p>Edit :</p>
  
  <p>Ok, I found that it is because it is called indirectly with this :</p>
  
  <pre><code>    private void Button_Click(object sender, RoutedEventArgs e)
      {
          xmpp1.OnConnected += new Xmpp.OnConnectedHandler(connect);
          xmpp1.IMServer = "***";
          xmpp1.IMPort = 5222;
          xmpp1.Connect("user1", "heslouser1");
          xmpp1.ChangePresence(1, "I'm here!");
      }
  </code></pre>
  
  <p>If I tried to change it directly with another button, it works as expected :</p>
  
  <pre><code>    private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          bindingChat = new BindingChat();
          bindingChat.leftText = "button pressed";
          ContentPanel.DataContext = bindingChat;
      }
  </code></pre>