views:

195

answers:

1

I have a datagrid. Within that datagrid, I have bunch of column headers styles. Inside the control template of this style, there is a button. I need to bind a command to that button.

Note that, there is also a TextBlock within the header style which I bind using element to element binding, as I will not have my viewModel in the header's dataContext.

If I use the same idea to bind the button command, it doesnt work. Am I missing something?

If this is unclear, please let me know and I will post sample code.

Thanks in advance!

A: 

Sample code always helps :-)

Remember that each data row in your grid is bound to an item with your datagrid datacontext. If your command does not exist in your item class (which it probably shouldn't) then it won't get bound correctly.

Can you trigger your command from the SelectedItem changed property of your datagrid, rather than an internal button? You can do this with the following code: http://thoughtjelly.blogspot.com/2009/12/silverlight-commands-data-grid-row.html

Best, Mark

Mark Cooper