wpf - MVVM: Editing a Customer. How to find a workspace with the same object and to create a new workspace from another workspace -


Just like, I am using MVVM and I want to add an update functionality.

Two problems arise (not addressed in the specified question):

  1. What is the best and easiest way to create a workspace from any other workspace?
  2. To know if there is already a workstation for editing the same client.

There are a lot of things going on here. Your question has two parts (if I'm missing nothing).

  1. How to forward the double-click operation to the command in your Vododal
  2. How to open a "workspace" in this sample (a workspace is just a tab, in this case ).

How to double click a list view item, MVVM style

There are many ways, but SO o on this question it is quite good :

I personally use the behavior of Marlongritch, so I will tell you how to do this:

   & Lt; Setter property = "ACB: Commandbackcommand" value = "{binding relative Sorcere = {relative resource mode = search explorer, exteriortype = {x: type user control}, path = data context. Edit classier command}" /> & Lt; Setter property = "acb: commandbackcomm.command parameter" value = "{binding}" /> & Lt; / Style & gt; & Lt; /ListView.ItemContainerStyle> & Lt; / ListView & gt;  

It will be bound to your EditCustomerCommand (which will be a RelayCommand) that you will need to setup in your AllCustomersViewModel.

Add a new workspace

This one is more difficult. You will see that there is an AddWorkspace in MainWindowViewModel, but we do not really have a reference to that ViewModel from AllCustomersViewModel.

I decided to do the best way to do this (for me) would be to create another interface called "IWorkspaceCommands" which will be used to create AllCustomersViewModel for a new workspace. This is mainly contrary to the suggestion of the previous responder of the Messenger view. If you like the Messenger viewpoint, you can use that place instead.

The main window viewmodel will actually implement it and when it will create AllCustomersViewModel, it will be passed.

  Public Interface IWorkspaceCommands {void AddWorkspace (Workstation ViewModel View); }  

And here is the basic implementation of the interface. Includes an investigation to see if the scene is already open , as requested (really simple!):

  #region IWorkspaceCommands Member Public Zero AddWorkspace (Workspace ViewModel View) {If (Workspace. Canton (see)) {Workspace. Add (see); } SetActiveWorkspace (see); } #endregion  

And finally, that's the relay command I was telling you in your AllCustomersViewModel (with some manufacturer modifications):

  IWorkspaceCommands _wsCommands; Public AllCustomersViewModel (CustomerProjectory Customer Repository, IWorkspaceCommands wsCommands) {_wsCommands = wsCommands; EditCustomerCommand = New Relay Commands (Edit Customers); ...} Public Zero EditCustomer (Object Customer) Customer {CustomerViewModel Customer Customer = CustomerViewModel; _wsCommands.AddWorkspace (customerVM); }  

It is too much because you are working with reference to the same view modal, which was used to make the AlkaCasters VVM model, when you edit it in a screen If it is, it is updated without incidental or messaging (good! But probably not strong enough).

There is a minor problem with the combo box that is not automatically selecting the value for the company / person, but it has been left as a drill for the reader.

As part of my package today, I am with a fully functional demo without additional charges

Hope it helps, / P>

Anderson


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -