I study WPF, the application is based on the principles of the mvvm pattern. I do not use any standard templates, all by myself, to clearly understand the principle of building applications. Faced a problem: I have two forms, form1 and form2 . On form1 there is a button for opening form2 , on which I fill in the data, after which I want to send this data for output to form1 . But it is impossible to implement it. To open form2 from form1 I form1 create an instance of the class:
form2 form = new form2() { DataContext = new MainWindowViewModel() }; In the same way, in form2 , after clicking the "send data" button (pressing the button is implemented from the ICommand interface) I would like the textBox to form1 this data right away.
form1 form = new form1 { DataContext = new MainWindowViewModel() }; <TextBox x:Name="testText" Width="100" HorizontalAlignment="Left" Height="100" Text="{Binding TestText1, UpdateSourceTrigger=PropertyChanged}"/> That is, I ran into 2 problems here: the data transfer itself and immediately viewing this data in form1 . For transmission, I tried to send text to the form1 constructor, create an open property there, but after my form.Show() code, form.Show() cannot get it into the textbox , as if after creating an instance, the context still does not change, but waits for the method to finish.
Tell me how to solve this problem (transmission and viewing)? I did those calls in the ViewModel.