39661

How can I pass objects to ViewModels using NavigationService?

The project I am working on is a desktop based WPF application. I have implemented the MVVM pattern in it. Also I am using Unity IoC and the Repository Pattern in it.

I have a problem in a master details type scenario. I navigate to the details Page(I have used IoC to expose the NavigationService in the ViewModel) but I dont know how can I get the employeeID in the EmployeeDetails ViewModel without breaking the MVVM pattern. I don't want to write anything in code behind.

Any pointers will be very helpful.

Regards.

Answer1:

Normally, you achieve this by exposing a property CurrentEmployee in your EmployeeMasterViewModel. This property is data bound to the currently selected item in the master list. You then bind the controls of the details page to the properties of CurrentEmployee.

Recommend

  • Dynamically Import Component From Variable (AngularJS)
  • Angular.js How to render a HTML tag from json file
  • Windows Phone: RemoveBackEntry after navigate failing
  • What should the value of Windows.Current.Content be after opening a secondary window?
  • AngularJS component with externally hosted templateUrl?
  • How to resize a pixmap with XLib?
  • untrusted HTML in d3.js v4 and AngularJS
  • Inheriting code-behind class from PhoneApplicationPage's subclass
  • UWP navigation (Template10), Pivot control, multiple frames
  • SQL Server Integrated Security from an Azure Web Site
  • SSRS 2008 - Sorting within a group
  • How to resolve dependencies from one gradle project to another gradle project in my Eclipse workspac
  • NRefactory: How do I access unresolved Named Arguments on a Property Attribute?
  • EF 4.1 DBContext AutoDetectChangesEnabled
  • MVC - @Html.CheckBoxFor
  • ImportError: cannot import name Pubnub
  • Where these are stored?
  • Mixing WebForms and MVC: What should I do with the MasterPage?
  • How to get links to open in the native browser in iOS Meteor apps?
  • Why use database factory in asp.net mvc?
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Ajax Loaded meta Tags
  • Master page gives error
  • WinForms: two way TextBox problem
  • Join two tables and save into third-sql
  • htaccess rewriting URLs with multiple forward slashes
  • How to model a transition system with SPIN
  • Display Images one by one with next and previous functionality
  • ORA-29908: missing primary invocation for ancillary operator
  • Web-crawler for facebook in python
  • R: gsub and capture
  • How do I rollback to a specific git commit
  • Matrix multiplication with MKL
  • A cron job substitute?
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs
  • Converting MP3 duration time