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 cod开发者_运维问答e.
Thanks in advance!
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
精彩评论