Deal of the Day

Home » Main » Manning Forums » 2007 » WPF in Action with Visual Studio 2008

Thread: Multiple windows app?

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Pages: 1 - Last Post: Mar 11, 2009 6:48 PM by: maxx.daymon
trifonius

Posts: 39
From: Netherlands
Registered: 7/11/07
Multiple windows app?
Posted: Mar 11, 2009 3:00 AM
  Click to reply to this thread Reply

First of all, I'd like to compliment the authors with the book. It's a great read, thorough explanations and clear examples.

I'm working on an application that needs to be able to edit data as well as showing reports on data. Since these two interfaces are very different I think I need multiple windows in this app, available from a menu or something.
Since there is no mention in the book of multiple windows, I wonder whether this is the recommended way to go. Is it advisable to use panels with controls and set their visibility (or something like that) instead? Seems like a bit of a hassle to me.

If it is fine to use multiple windows, how can I display them from selecting a menu item?

Thanks

maxx.daymon

Posts: 31
From: Colorado
Registered: 7/25/06
Re: Multiple windows app?
Posted: Mar 11, 2009 4:47 AM   in response to: trifonius in response to: trifonius
  Click to reply to this thread Reply

Thank you for the compliments!

I had a bit of trouble with the code formatting in the forum, so I answered your question on my dead blog. (Well, it appears that it's not quite dead yet, it's feeling much better now...)

http://www.exotribe.com/maxx/2009/03/11/using-windows-in-wpf/

Let me know if you have any other questions!

trifonius

Posts: 39
From: Netherlands
Registered: 7/11/07
Re: Multiple windows app?
Posted: Mar 11, 2009 5:33 AM   in response to: maxx.daymon in response to: maxx.daymon
  Click to reply to this thread Reply

Thanks so much for your helpful reaction!

I'll play with the material you explained and if I have more questions I'll ask through this forum.

Thanks again!

trifonius

Posts: 39
From: Netherlands
Registered: 7/11/07
Re: Multiple windows app?
Posted: Mar 11, 2009 10:20 AM   in response to: maxx.daymon in response to: maxx.daymon
  Click to reply to this thread Reply

OK, one thing that is not clear to me is how can I pass values from the new window to the parent window?

I have three textboxes in the new window that have their Text property set to a Path on the DataContext of the window. This works fine. Now I would like to edit these values and send them to the parent window, but all I can see using the ShowDialog() method is that I can get a nullable bool as a DialogResult. How can I pass the Textbox values? Or do I have to handle all operations in the .cs code of this window?

Thanks again!!

Message was edited by:
trifonius

maxx.daymon

Posts: 31
From: Colorado
Registered: 7/25/06
Re: Multiple windows app?
Posted: Mar 11, 2009 6:48 PM   in response to: trifonius in response to: trifonius
  Click to reply to this thread Reply

If you follow the OpenFileDialog sort of model, you would put a public property on the Window class you created, and set the resulting object before you close the window, like this:

(in EditWindow.cs)
private void Ok_Click(object sender, RoutedEventArgs e)
{
PropertyOfReturnedObject = new MyClass(value1, value2, value3);
DialogResult = true;
Close();
}

(in Window.cs)
if ((bool)editWindow.ShowDialog)
{
Save(editWindow.PropertyOfReturnedObject);
}

A more WPF-ie approach would be to simply set the object to edit as the data context of the new window, and put a property transmogrifier that casts it for you:

(in EditWindow.cs)
public MyClass MyData { get { return (MyClass)DataContext; } }

then, Save (editWindow.MyData);

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor