Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Problems with MVVM and hierarchy

$
0
0

I'm always stuck with MVVM when I'm challanged to solve the following problem:

Let's say I've implemented a Viewmodel named MyCustomersViewModel which contains all stuff for some Window containing a Grid with a list of my Customers.

Each row of the Grid contains a custom UserControl with Textboxes, an Image, some other stuff and let's say a "Delete" button.

For each Row i created a Viewmodel, let's  call it CustomerViewModel, the MyCustomersViewModel contains a Collection of those.

Everything works fine, i can change each customer, i can add new ones from outside because this is implemented in the parent MyCustomersViewModel. But what is with my "Delete" button? There is one for each row, but the command i would bind to it would have to change the parent viewmodels collection, so each child would have to know its parent.

Another way would be to implement the Command in the MyCustomersViewModel but then it needs an parameter, which element to delete, so I needed to pass a key or something as parameter from xaml to the command. Also not that good.

How to solve those problems better?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>