0

Well, I have an instance of my Logic class in MainWindow. There are buttons lead to other windows where I want to use Logic methods. Should I somehow use only one instance or create new one in each window? Just don't understand how it works.

Main Window

public Logic data;
public MainWindow()
{
    InitializeComponent();
    data = new Logic();
}
public void OpenAddWindow(object sender, RoutedEventArgs e)
{
   tForm win2 = new tForm();

    win2.ShowDialog();
}

ChildWindow

public Logic logic = ((MainWindow)App.Current.MainWindow).data;

public TForm()
{
    InitializeComponent();
}
public void first_ButtonClick(object sender, RoutedEventArgs e)
{
    logic.AddNew();

    this.Close();
}
Muhammad Sulaiman
  • 2,399
  • 4
  • 14
  • 28
ctg
  • 1
  • 2
  • That decision would probably depend on whether the object stores instance data, like a "current status" or an "IsNew" property or so. See also https://stackoverflow.com/questions/169378/method-can-be-made-static-but-should-it – Stefan Wuebbe Sep 12 '22 at 13:13

0 Answers0