Solved

MVVM - "Add New"  Window

Posted on 2011-03-20
4
651 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 500 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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