Solved

MVVM - "Add New"  Window

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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