Xaml.cs file:
<textarea style="width: 657px; height: 484px; line-height: 1.5; font-family: Courier New; font-size: 12px;">using system;using system.timers;using system.windows;using system.windows.forms;namespace ControlUsed{Public Partial class MainWindow {public MainWindow () {monitor.partevent + = onstep;//Registers a function in this class with the Mon Itor the static class in the Partevent event. } public void Onstep (Object Sender,messageargs message) {Application.Current.Dispatch Er. Invoke (new Action () = {Mytextblock.text = message. txtmessage;//setting the property of the control in XAML)); } }}</textarea>
Messageargs class:
Public <textarea style="width: 657px; height: 224.8px; line-height: 1.5; font-family: Courier New; font-size: 12px;">class Messageargs:eventargs {public Messageargs (String message) {this. txtmessage = message; public string Txtmessage {get; set;} }</textarea>
Monitor Static class:
Public <textarea style="width: 657px; height: 449.6px; line-height: 1.5; font-family: Courier New; font-size: 12px;">Static class monitor {public static event eventhandler<messageargs> partevent;//defined in monitor parameter is Messageargs object public static void Infunction (String message) {var messagearg = new Message Args {txtmessage=message}; if (partevent! = null)//If the function is registered to Partevent in the MainWindow constructor, it is not null {partevent (New object), Messagea RG);//Trigger event, execute all registered functions}} public static bool Monitorcenter () {infunction ("change");//Outside Modify TextBlock's Text}} in class</textarea>
C # uses events to invoke controls in the WPF main window across classes