Reputation: 159
How can I call the Zamkniecie() file Window1.cs not the new object as I showed in the method Window_Closed(), but the object you are currently working with a file MainWindow.cs? Components of methods Zamkniecie() have been created in the file MainWindow.xaml
File: Window1.cs
namespace AllSportsBets102
{
public partial class Window1 : Window
{
public Window1(DataGrid zdg, List<Data2> dsx)
{
InitializeComponent();
}
private void Window_Closed(object sender, EventArgs e)
{
MainWindow mw = new MainWindow();
mw.Zamkniecie();
}
}
}
File: MainWindow.cs
namespace AllSportsBets102
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void Zamkniecie()
{
InfoStackPanel.IsEnabled = true;
KuponStackPanel1.IsEnabled = true;
KuponStackPanel2.IsEnabled = true;
FiltrStackPanel.IsEnabled = true;
WszystkieZdarzeniaStackPanel1.IsEnabled = true;
WszystkieZdarzeniaStackPanel2.IsEnabled = true;
KuponLabel.IsEnabled = true;
WszystkieLabel.IsEnabled = true;
InfoLabel.IsEnabled = true;
StackPanel1Copy.IsEnabled = true;
StackPanel2Copy.IsEnabled = true;
}
}
}
Upvotes: 0
Views: 279
Reputation: 435
Here are a few options:
I prefer option 5, if it's possible because it more closely allow each class to manage itself. If you only want to call Zamkniecie when Window1 closes, you should be able to recognize that from MainWindow. Here's a code snippet that would go in MainWindow:
Window1 window1 = new Window1();
window1.ShowDialog();
Zamkniecie();
Note: Which file these classes are in makes no difference as long as they are in the same namespace.
Upvotes: 1
Reputation: 143
I know this might be redundant, but the quickest way would be to add an
using MainWindow.cs;
at the top of the Window1.cs file
Upvotes: 0