Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MVVM - "Add New"  Window

Posted on 2011-03-20
4
Medium Priority
?
654 Views
Last Modified: 2012-05-11
I am using MVVM / WPF in my solution.    I would like to be able to click on a "Add Address" button to open a new window and allow the user to add a new address.   Of course the address must be linked to a particular Organisation.    

This is what I have working already

1) I have a Organisation details form which has the Main Organisation Details, Addresses, Contacts.

2) I have the following. All  of which are working in isolation.  
"Organisation Details" View / ViewModel,  
"Organisation"  View / ViewModel
"Address List" View / ViewModel
"Address View" View / ViewModel.
 
3) The Organisation Details View Model contains the Organisational View Model and the Address List View Model.
I pass in a reference to the Organisation into the both of these models.  The address list uses this to get the addresses for that organisation.

4) I can currently see and edit the Organisation  and edit the existing addresses.

What I need now is to open a new window to allow the user to add a new address.  

So Questions
Q1)  How and where do I place the code to open the new window
Q2)  How and where do I pass in the current Organisation Reference to the new window so the new address gets added to the Organisation.


0
Comment
Question by:Kevin Robinson
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35179265
Check the following example for opening a new window

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bced6b99-c8ce-425e-9b34-967a361cedd2

You can add a new constructor which takes the organizationid as parameter so that

var newWindow = new MyNewWindow(OrgID);
0
 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35179406
I was looking more for a MVVM example.
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 2000 total points
ID: 35180081
I used code-behind to navigate around the application - my argument being that moving from one View to another can reasonably be considered as part of the View rather than the ViewModel.
The app that the following example comes from used Pages rather than Windows, but the idea should be the same.
This code opens a new Order page for the selected item in the customer list view and passes the Customer instance to the OrderEntry view constructor.

    Private Sub OpenOrder()
        If lstCustomers.SelectedItem Is Nothing Then Exit Sub
        Mouse.OverrideCursor = Cursors.Wait
        Dim nav = NavigationService.GetNavigationService(Me)
        nav.Navigate(New OrderEntry(CType(lstCustomers.SelectedItem, Models.Customer).ID))
    End Sub

Hope this helps.
0
 
LVL 3

Author Closing Comment

by:Kevin Robinson
ID: 35197069
Thanks
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question