Universal Windows Platform (UWP)
A Microsoft platform for building and publishing apps for Windows desktop devices.
2,971 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
c# : Get EventHandler Change Notification without Creating Instance or Making it static
Public class A
{
public EventHandler KeyboardCloseEventHandlerTest;
private void someMethod(object sender, EventArgs e)
{
KeyboardCloseEventHandlerTest?.Invoke(sender, e);
}
}
Public class B
{
public EventHandler KeyboardCloseEventHandlerTest1;
private void Tesssss(object sender, EventArgs e)
{
}
}
I need class A EventHandler to registered in Class B and Fire Class Method.
I can't make anything static not create a instance. More Importantly it should not cause performance Issue.
Hi,
Welcome to our Microsoft platform!
You can use unity container ,example
using Unity;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public interface IClass
{
void method();
}
public class A : IClass
{
public void method()
{
MessageBox.Show("A");
}
}
public class B : IClass
{
public IClass IClass { get; set; }
UnityContainer container = new UnityContainer();
//create Class A
IClass classA;
public B()
{
container.RegisterType<IClass, A>("NameA");
classA = container.Resolve<IClass>("NameA");
}
public void method()
{
MessageBox.Show("B");
}
}
Thanks.