I had 2 projects in one solution. Project 1 needs a class from project 2 and project 2 needs a class of project 1.
The problem is: If I add a reference of project 1 in project 2, I cannot add a reference of project 2 in project 1 .
But I needed to access main window's label from different project class. This is how I achieved it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClassfromProject2 | |
{ | |
public static event Action<string> MessageReceived; | |
// calling the message displayer | |
public ClassfromProject2() | |
{ | |
Broadcast("this is the sample message"); | |
} | |
internal static void Broadcast(string message) | |
{ | |
if (MessageReceived != null) | |
{ | |
MessageReceived(message); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using Project2; | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
ClassfromProject2.MessageReceived += messagetext => | |
{ | |
status_lable.Content = messagetext; | |
}; | |
} | |
} |
Excellent!!!!.... Thank you very much.. it works for me. Keep it up
ReplyDelete