开发者

WPF: Opening 2 pages at one Window at the same time

开发者 https://www.devze.com 2023-01-22 16:30 出处:网络
I have a problem loading two pages at the same time in one window. Here\'s the scenario. I have a MainWindow.xaml and I have two page files which are LeftPage.xaml and RightPage.xaml. I used frame co

I have a problem loading two pages at the same time in one window.

Here's the scenario. I have a MainWindow.xaml and I have two page files which are LeftPage.xaml and RightPage.xaml. I used frame controls of VS 2010 into my MainWindow.xaml in order to separate the two pages in one Window.

Assume when we have a code in LeftPage.xaml.cs as textBox1.Text = textBox2.Text and we also have an eventhandler of textBox2.TextChanged, whatever you type in textBox2 will be automatically be displayed on textBox1 whenever the user changed the inputted data on textBox2.

Now, I would like to try to display the current data that is loaded in LeftPage.xaml into the RightPage.xaml. Assume we have a textBox3 in RightPage.xaml

I tried instantiati开发者_StackOverflow中文版ng LeftPage LP = new LeftPage(); this.textBox3.Text = LP.textBox1;

It won't display the current data that I have in textBox1. I tried databinding, MVVM pattern but still it does not work. Is it possible to get the current running data in the left page to the right page? Thanks


You need to keep a reference to the actual page, not a new instance of the page.

When you do this: LeftPage LP = new LeftPage() you are creating a new empty instance of the page object.

If you are not using the frame to navigate between pages, is better the construct UserControls instead of pages and host them directly in the window.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号