title: Change a label on a form from another class
body: <p>My problem might be a dumb one but after hours of searching, I have to ask you for help.
  I have a WPF form <code>LoginPage</code> that features a Label ,(called AlertText) that displays messages to the user and I need to change his content from another class.
  To change the content I use <code>AlertText.Content = "content"</code> and it works perfectly.
  But when I'm on another class and I want to change it that doesn't do anything.
  Both class are under the same namespace. </p>
  
  <p>I've tried this :</p>
  
  <pre><code>LoginPage lg = new LoginPage();
  lg.AlertText.Content = "content";
  </code></pre>
  
  <p>The object is created but the second line isn't executed.
  I've tried to create a public function <code>SetAlertText()</code> in my <code>LoginPage</code> class but that doesn't worked either.
  I made it static and called it by <code>LoginPage.SetAlertText()</code> but same problem persists.</p>
  
  <p>I've added this in my <code>LoginPage</code> :  </p>
  
  <pre><code>public static LoginPage instance;
  
          public LoginPage()
          {
              instance = this;
          }
  </code></pre>
  
  <p>And called it by </p>
  
  <pre><code>LoginPage.instance.SetAlertText();
      and 
  LoginPage.instance.AlertText.Content = "content";
  </code></pre>
  
  <p>but neither worked.</p>
  
  <p>I also tried : </p>
  
  <pre><code>public LoginPage()
              {
                  instance = new LoginPage();
              }
  </code></pre>
  
  <p>What can I do ?</p>
  
  <p>Edit :
  Here's the full code of both classes : </p>
  
  <pre><code>namespace TMClientWPF
  {
      /// &lt;summary&gt;
      /// Logique d'interaction pour LoginPage.xaml
      /// &lt;/summary&gt;
      public partial class LoginPage : Page
      {
          ClientTCP client;
          bool isConnected = false;
          public RegisterPage registerPage;
          public static LoginPage instance;
  
          public LoginPage()
          {
              instance = this;
              InitializeComponent();
  
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              AlertText.Content = "";
              try
              {
                  if (isConnected == false)
                  {
  
                      client = new ClientTCP();
                      client.Connect();
  
                      isConnected = true;
                  }
  
                  client.SEND_LOGINS(UsernameText.Text, PasswordText.Password.ToString());
              }
              catch (NullReferenceException)
              {
                  AlertText.Visibility = Visibility.Visible;
                  AlertText.Content = "Failed to connect to server, please try again later.";
              }
          }
  
          private void Button_Click_1(object sender, RoutedEventArgs e)
          {
              registerPage = new RegisterPage();
              this.NavigationService.Navigate(registerPage);
          }
  
          private void Button_Click_2(object sender, RoutedEventArgs e)
          {
              Application.Current.Shutdown();
          }
  
          public void SetAlertText(string text)
          {
              AlertText.Visibility = Visibility.Visible;
              AlertText.Content = "Welcome Home";
          }
      }
  }
  </code></pre>
  
  <p>///////////////////////////////</p>
  
  <pre><code>namespace TMClientWPF
  {
      public class ClientHandlePackets
      {
          public static ByteBuffer playerBuffer;
          private delegate void Packet_(byte[] data);
          private static Dictionary&lt;long, Packet_&gt; packets;
          private static long pLength;
  
          public static void HandleData(byte[] data)
          {
  
              InitializePackets();
              byte[] Buffer;
              Buffer = (byte[])data.Clone();
  
              if (playerBuffer == null)
              {
                  playerBuffer = new ByteBuffer();
              }
              playerBuffer.WriteBytes(Buffer);
              if (playerBuffer.Count() == 0)
              {
                  playerBuffer.Clear();
                  return;
              }
  
              if (playerBuffer.Length() &gt;= 8)
              {
                  pLength = playerBuffer.ReadLong(false);
  
                  if (pLength &lt;= 0)
                  {
                      playerBuffer.Clear();
                      return;
                  }
              }
  
              while (pLength &gt; 0 &amp; pLength &lt;= playerBuffer.Length() - 8)
              {
                  if (pLength &lt;= playerBuffer.Length() - 8)
                  {
                      playerBuffer.ReadLong(); //read out the packet identifier
                      data = playerBuffer.ReadBytes((int)pLength); //get the full package length
                      HandleDataPackets(data);
                  }
                  pLength = 0;
                  if (playerBuffer.Length() &gt;= 8)
                  {
                      pLength = playerBuffer.ReadLong(false);
  
                      if (pLength &lt; 0)
                      {
                          playerBuffer.Clear();
                          return;
                      }
                  }
              }
          }
  
          private static void HandleDataPackets(byte[] data)
          {
              long packetIdentifier;
              ByteBuffer buffer;
              Packet_ packet;
  
              buffer = new ByteBuffer();
              buffer.WriteBytes(data);
              packetIdentifier = buffer.ReadLong();
              buffer.Dispose();
  
              if (packets.TryGetValue(packetIdentifier, out packet))
              {
                  packet.Invoke(data);
              }
  
  
          }
  
          private static void InitializePackets()
          {
              packets = new Dictionary&lt;long, Packet_&gt;();
              packets.Add((long)ServerPackets.S_INFORMATION, PACKET_INFORMATION);
              packets.Add((long)ServerPackets.S_EXECUTEMETHODONCLIENT, PACKET_EXECUTEMETHOD);
              packets.Add((long)ServerPackets.S_LOGCALLBACK, Packet_LogCallback);
          }
  
          #region packets
  
          private static void PACKET_INFORMATION(byte[] data)
          {
              ByteBuffer buffer = new ByteBuffer();
              buffer.WriteBytes(data);
  
              long packetIndentifier = buffer.ReadLong();
  
              string msg1 = buffer.ReadString();
              string msg2 = buffer.ReadString();
              int level = buffer.ReadInteger();
              buffer.Dispose();
              ClientTCP.instance.SEND_THANKYOU();
          }
  
          private static void PACKET_EXECUTEMETHOD(byte[] data)
          {
              ClientTCP client = new ClientTCP();
          }
  
          private static void Packet_LogCallback(byte[] data)
          {
              ByteBuffer buffer = new ByteBuffer();
              buffer.WriteBytes(data);
              buffer.ReadLong();
              string message = buffer.ReadString();
              string username = buffer.ReadString();
              buffer.Dispose();
              if(message == "true")
              {
                 // LoginPage.SetAlertText("Welcome Home.");
              }
              else
              { 
                  LoginPage lg = new LoginPage();
                  LoginPage.instance.SetAlertText("Invalid logins.");
              }
          }
  
          #endregion
  
      }
  }
  </code></pre>