how to dynamically add button to SilverLight datagrid
- by Grayson Mitchell
I have a datagrid that I want to add a button/s to at runtime. I have managed to do this with the below code:
DataGridTemplateColumn templateCol = new DataGridTemplateColumn();
templateCol.CellTemplate = (System.Windows.DataTemplate)XamlReader.Load(
@"<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Button Content='" + item.Value.Label + @"'/>
</DataTemplate>");
_dataGrid.Columns.Add(templateCol);
The problem is that I can't work out how to add a click event. I want to add a click event with a parameter corresponding to the row id...