how to dynamically add button to SilverLight datagrid

Posted by Grayson Mitchell on Stack Overflow See other posts from Stack Overflow or by Grayson Mitchell
Published on 2010-03-16T01:23:23Z Indexed on 2010/03/16 1:29 UTC
Read the original article Hit count: 383

Filed under:

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...

© Stack Overflow or respective owner

Related posts about silverlight-3.0