user3062970
user3062970

Reputation: 13

Move data between windows?

I have been trying to move data from one WPF window to another while both are open without making a new instance. This feels like it should be really easy but after hours of researching I cant get anything to work.

Here is what I have tried so far. This works, however, it creates another mainform.

Dim mainform As New MainWindow
mainform.TextBox3.Text = TextBox1.Text
mainform.Show()

if I try this without the word new it gives me an error.

I am totally puzzled by this.

Upvotes: 1

Views: 175

Answers (2)

Ryan Burbidge
Ryan Burbidge

Reputation: 192

Use MVVM pattern. Your ViewModel will contain all data that you need to be copied to the other window. Your Window class will have a constructor that accepts a ViewModel. Now just write a copy constructor for your ViewModel, create a new Window with that copy, and you're done.

Upvotes: 1

B.K.
B.K.

Reputation: 10172

I suggest you take a look at the MVVM concept, which will give you a great foundation for understanding how to setup your WPF application. It appears that you lack the basic understanding of WPF components necessary to achieve proper results. While there are many ways of developing WPF application, MVVM will provide that necessary base. Moreover, I suggest looking at MSDN and other websites that would provide beginner tutorials. By reading your question, I feel that you're trying to do something without really know what you're doing. I don't suggest that it's a bad thing in any way - I believe that the best way to learn is by doing, but you need to acquire some guidance in a manner of tutorials or perhaps a book.

Upvotes: 1

Related Questions