Click here to Skip to main content
15,064,072 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In My WPF application,

I am having two user controls.

1.Usercontrol1
2.Usercontrol2

And I am using these two Usercontrols in my mainwindow like this.

mainwindow.xaml

In my mainwindow I am using Usercontrol1 like this.
XML
<my:Usercontrol1 Margin="0,0,0,17" Name="loginUserControl1" />

for example In my Usercontrol having one string,one button having button_click event.

When ever user click on the button we are showing the Usercontrol2 like this.
C#
private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
this.content=new Usercontrol2();
}

Up to here working fine.

My question is when the usercontrol2 is loading I need pass my Usercontrol1 string value to the usercontrol2.

Usercontrol2 is dependent on the usercontrol1.

How can I achieve this.

Please share me the solution.
Posted
Updated 5-Mar-13 18:26pm
v2

1 solution

In your Click event you have access to the string value from userControl1 (because this code is in UserControl1)

So if you add a property to UserControl2 called myStringValue

you can change your code slightly to:
C#
var uc = new UserControl2();
uc.myStringValue = this.yourTextBoxName.Text;
this.content = uc;
   
Comments
Aarti Meswania 6-Mar-13 1:10am
   
5+ :)
D-Kishore 6-Mar-13 1:21am
   
Thank you so much Max,
Its works fine.
mine 5+

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