Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have two WPF windows, that is MainWindow and Window1. In MainWindow i have a textbox(textbox1) and a button, in Window1 i have a textbox(textbox2).

What i am trying to accomplish is that when i click the button, whatever is typed in textbox1 is now displayed in textbox2.

my xaml i believe is correct for both windows and i have added the "private void button_click_1....." in my MainWindow.cs. however when ever i try to type the action:

textbox2.Text = textbox1.Text;

it does not recognize textbox2


I am fairly new to WPF and c# so any assistance would be appreciated. Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 26-May-14 2:30am    
This is barely related to WPF, rather to general OOP. It looks like you don't really understand types and instances of types, as well as instance members.
—SA
[no name] 26-May-14 5:55am    
Do a search for "pass data between forms" and start studying.

Please see my comment to the question and my past answer: Repeat wpf Datagrid data in another window text boxes[^].

Please learn some OOP basics, otherwise you are going to too advanced stuff without understanding of fundamentals. Eventually, it may end up with a lot of frustration.

—SA
 
Share this answer
 
First, Create two viewModels for both window files.

Define one property which will get and set values from textbox
in each ViewModel.

Create NavigationService.cs class for opening window:
Let NavigationService.cs

Now put following code in that class file.

C#
public void ShowWindow1Screen(Window1ViewModel window1ViewModel)
       {
           Window1= new Window1();
           Window1.DataContext = window1ViewModel)
           Window1.Owner = nicknameView;
           Window1.ShowDialog();
       }

then.


Create instance of NavigationService.cs class MainWindowViewModel file.
then
C#
Window1ViewModel window1ViewModel = new Vindow1ViewModel();
window1ViewModel.Name = MainWindowTextValue;
NavigationService navigationService = new NavigationService();
navigationService.ShowWindow1Screen(window1ViewModel);
 
Share this answer
 
v2

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