Solved

MVVM - "Add New"  Window

Posted on 2011-03-20
4
639 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
Comment Utility
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
Comment Utility
I was looking more for a MVVM example.
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now