Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVVM - "Add New"  Window

Posted on 2011-03-20
4
Medium Priority
?
652 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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