0

I have created WPF Browser Application and added Page and a Window. On click of button in Page it opens the Window with the list of details in a DataGrid. I want to assign the values from DataGrid of Window to the Page Controls.

The values are not assigned to the Page controls with the following code in Window code behind (Window1.xaml.cs)

private void DataGrid1_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
{ 
 Page1 page = new Page1(); 
 page.txtName.Text = "GridValue1";
 this.Close(); 
}

When I DoubleClick, the values from Wiindow1 Datagrid should be assigned to controls of Page1. I am not getting the right object of the page to assign txtName.text with DataGrid value of Window1.

Thanks a lot in Advance...

dlev
  • 48,024
  • 5
  • 125
  • 132
CPK_2011
  • 1
  • 1

1 Answers1

0

You should use MVVM architectural pattern in your app. Then just share/copy-to-window your ViewModel (which is responsible for holding values and coordination between View and Model) between Page and Window. So you will be able to correctly handle synchronization in both ways.

UPDATE

In your case in the event handler you need to walk up from DataGrid.Parent and so on until you find the parent page. You will need to use this approach on finding visual parents.

Community
  • 1
  • 1
Eugene Cheverda
  • 8,760
  • 2
  • 33
  • 18
  • I don't want to use MVVM Pattern. I just want the right object of the Page. – CPK_2011 May 24 '11 at 08:45
  • I have set like `Window w = new Window(); w.Owner = this; w.Show();`. But in my scenario, I am calling WPF Window from WPF Page. How can I do this? This is not working for me to set Page as Parent for Window.... – CPK_2011 May 24 '11 at 11:30
  • You may inherit new class from Window and add property like Parent or any other that will hold creator of window. It will look and operate like Window having additional property that will suite your needs. – Eugene Cheverda May 24 '11 at 14:48
  • I could not get it actually....Is there any sample code for inheriting a new class from Window and adding property like Parent.. – CPK_2011 Jun 09 '11 at 16:34