Question

I have a program in MVVM. In this program i have a view with a DataGrid. In this datagrid i have to show something like this:

enter image description here

The user mark some cells and after MouseUp, should be created a button over this selected cells. The first Problem here is, how to get the Column and the Row. It is in the SelectedCellsChanged-Event Argument. With help from the WPF MVVM Light i can give my ViewModel the Event and the Arg, but my workmate had already problems with visual elements in a ViewModel(He was get a error in the visual tree). And i know that a visual element should not be in a VM. Can anyone here give me a way to get this Column and Row-Spawn?

My second problem that i can't imagine me how to create the buttons in the correct cell. If i think right is it possible to build a new VM for every Button(with Property StartRowSpawn, EndRowSpawn, StartColumnSpawn, EndColumnSpawn) or for each cell?

Can you give me tip, how to solve that?

I thinked about a grid too. Get position while MouseDown and MouseUp and then find the Grid.Column and Grid.Row for that.

Edit

Okay i done my first problem with Interfaces, but i already have my second problem. Can anyone help me there?

No correct solution

OTHER TIPS

I would rethink why you need to do this(or maybe you can explain more why to need buttons like this). What I do when I need to change the design of data in a data grid is use an alternate datatemplate or the details datatemplate for the datagrid row to chnage the format of the infomration, then you can use the same view model. You can bind the column spans to properties in your viewmodel but it gets difficult if you want the button quantities to be dynamic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top