DataGrid row button click

2011-12-06 Thread Greg Keogh
Folks, I think I've outsmarted myself. I have a DataGrid bound with a template column containing a Button and it's all looking quite acceptable. Now I'm a bit flummoxed, as when one of the buttons is clicked I have to find out which object in the data source is behind the row containing the

RE: DataGrid row button click

2011-12-06 Thread Steven Nagy
If you are using MVVM, then you can bind your button to a command on the object being bound to. From: ozsilverlight-boun...@ozsilverlight.com [mailto:ozsilverlight-boun...@ozsilverlight.com] On Behalf Of Greg Keogh Sent: Tuesday, 6 December 2011 8:04 PM To: 'ozSilverlight' Subject: DataGrid

RE: DataGrid row button click (answered?!)

2011-12-06 Thread Greg Keogh
To find the DataGridCell that contains the clicked button I found that a simple iteration up through the Parent properties of the sender eventually reaches the cell. I don't go to the trouble of using the VisualTreeHelper as the Parent property was enough in this case (I was doing that in a WPF

RE: DataGrid row button click (answered?!)

2011-12-06 Thread Steven Nagy
The row being acted upon is what actually has the Command object, so you're already in the context of what you want to get information from ViewModel: Public ObservableCollectionFooModel Foos { get; set; } FooModel: public string Name { get; set; } public RelayCommand AddWidget { get;

Re: DataGrid row button click

2011-12-06 Thread Jordan Knight
You should be able to grab the data context from sender without iterating the visual tree at all. Data contexts flow down automatically. Cheers, Jordan. On 06/12/2011, at 11:03 PM, Greg Keogh g...@mira.net wrote: Folks, I think I’ve outsmarted myself. I have a DataGrid bound with a

Re: DataGridCheckBoxColumn (fixed?!)

2011-12-06 Thread Jordan Knight
Create a user control and place it in the cell. Have a dependency property on it to publish the select color back to where you need... Cheers, Jordan. On 06/12/2011, at 7:07 PM, Greg Keogh g...@mira.net wrote: Now that’s solved, I have an even more ambitious thing to try. I want to

RE: DataGridCheckBoxColumn (fixed?!)

2011-12-06 Thread Greg Keogh
It’s all working now. It turns out I didn’t need to walk up anywhere for the DataContext, as the I managed to embed a C1 colour picker control into the template cell and bind it directly to the Colour property. The screen shot I’ve pasted below (if your email can see it) shows how I’ve bound a