Kirti Deshpande

Kirti Deshpande

  • 1.5k
  • 108
  • 14.8k

How to access viewmodel class from one project in another project in c

May 16 2022 6:09 AM

My solution contain Winform and WPF project. Project A is WinForms application. Project B is WPF application.

I have one Button_Click event in class A from project A. When I click on button(win form App) one Tab item should add in Project-B at RunTime(WPF application) Winforms App hosting a WPF control

I added all the logic for adding tab item in viewmodel . Need to establish a communication between winform and wpf application.

How should I achieve this?

Editor.cs(From Winform App - Project A)

Approch1 - Event raised to notify the ViewModel

private void button1_Click(object sender, EventArgs e)
{AddNewTabPage?.Invoke(this, true);
}

Approch2 :Calling ViewModel method through interface

private void button1_Click(object sender, EventArgs e)
{Interfaceobj.AddTabItemMethod();
}

EditorViewModel.cs(WPF application-Project B)

private void AddTabItemMethod()
{AddTabItem();
}