Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have two windows. I am wondering if it is possible to link the action of a button in Window1 to a stackpanel which is in th MainWindow.

Such as the button in Window1 should add 1 rectangle to the MainWindow stackpanel?

Just need a hint or something to go on. Havent tried linking buttons and other stackpanels between two seperate windows before.

I am programming in C#.

eg:

this code is for button1 in Window1: (this is just part of the code):

C#
private void button1_Click(object sender, RoutedEventArgs e)
{
    string tempDisks = comboBox.Text;
    if (tempDisks == "1")
    {
        stackPanel1.Children.Add(rectangle1);
    }
}


Where stackpanel1 is in the MainWindow.

Thanx for any responses
Posted
Updated 7-Mar-11 19:11pm
v2
Comments
furyous 7-Mar-11 22:44pm    
when you initialize your other window just send the parent window as a parameter and then access it that way for example then you could do m_Parent.FunctionCall();
furyous 7-Mar-11 22:52pm    
sorry this might make more sense to you

public partial class SecWindow : Window
{
private MainWindow m_Parent;

public SecWindow(MainWindow parent)
{
InitializeComponent();
m_Parent = parent;
m_Parent.FunctionCall();
}
}


of course MainWindow would be whatever window you are trying to pass
Sagotharan Jagadeeswaran 8-Mar-11 23:59pm    
very nice,.

furyous add ur solution to solution column.

furyous already answered this question.
 
Share this answer
 
C#
public partial class SecWindow : Window
{
    private MainWindow m_Parent;
    public SecWindow(MainWindow parent)
    {
        InitializeComponent();
        m_Parent = parent;
        m_Parent.FunctionCall();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900