Reputation: 2363
I'm sorry to post this question because there's a lot of relative subjects with this one but unfortunately none of them couldn't helped me !! so I have an application that contains two wpf windows (MainWindow() and Window1()), what i exactly want to achieve is to control the window1 properties from the MainWindow().. for example i want to clear a listbox items from window1 every time i click on Button1 from the MainWindow !! I also want to have a full access to the methods, fields and properties that exits in the MainWindow from window1.
Upvotes: 1
Views: 1958
Reputation: 1189
Where is the problem ? I dont see any question.
Maybe you want to start by saving a ref of Window1 in MainWindow.
Window1 window1 = new Window1();
window1.show();
From there do what you need done :
window1.foo();
window1.bar();
window1.foobar = "Title";
Edit : some clarification, because OP seems to be a beginner :
public class MainWindow
{
private Window1 window1;
public void CreateWindow()
{
window1 = new Window1();
window1.show();
}
private void DoStuffWithWindow1()
{
window1.foo();
window1.bar();
window1.foobar = "Title";
}
}
Upvotes: 1
Reputation: 49013
What you could do is to add public properties/method that allows access to your Window1
class from MainWindow
.
For instance, if you want to clear a list in Window1
from MainWindow
, add the following method to Window1
:
public void ClearList()
{
// Clear your list here
}
Of course you'll need your MainWindow
to know about Window1
, but as the name suggests, I assume MainWindow
is the main window so it creates the Window1
instance.
So you should have a reference to Window1
in MainWindow
. In MainWindow
, just call:
this.myWindow1.ClearList();
Upvotes: 2