MVVM opens a new workspace from another workspace (instead of the main ControlPanel)

I am learning MVVM using a sample created by Josh Smith at http://msdn.microsoft.com/en-us/magazine/dd419663.aspx I wanted to add update functionality to my existing code.

Similar to how the user sees the data in the All Clients grid, the user can edit a specific record by double-clicking it, double-clicking it will open a new tab (same view / view mode used for the new client). I don't know how to do this, I need to call it through mainwindowviewmodel or is there some other way.

Thanks everyone and happy programming

GAurav Joshi

+1


source to share


1 answer


It's a bit related, so let's take one at a time:

The first thing you need to do is let the View Model know which item is selected. To do this you will need to add the IsSelected property for the client

public bool IsSelected { get; set; }

      

Strike> (Edit: As pointed out to me already, the CustomerViewModel class already has this property, so the above is not required for this particular project, although it does.)

Then you need to bind the IsSelected property to the items in the ListView. One way to do this is with style that is customer-focused. Something like that:



<Style x:Key="CustomerListStyle" TargetType="{x:Type ListViewItem}">
    <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
</Style>

      

Then assign this style using the ItemContainerStyle on the ListView:

<ListView ItemContainerStyle="{StaticResource CustomerListStyle}" ...>

      

To be able to edit the selected customer, you must add the EditCostumer command for the AllCustomersViewModel. Inject this command using the RelayCommand to display the edit view for the selected item.

You can use LINQ to find a client with IsSelected == true

.

+1


source







All Articles