Hello, I'm having trouble figuring out how to add a button dynamically in a radgridview.
I'm porting over working code that used the stock WPF DataGrid control. This is the method I *used* to use:
private DataGridTemplateColumn GetButtonColumn(IListPropertyInfo i)
{
var buttonTemplate = new FrameworkElementFactory(typeof(Button));
buttonTemplate.SetBinding(Button.ContentProperty, new Binding(i.columnName));
buttonTemplate.SetValue(Button.StyleProperty, DefaultStyles.GridColumnButtonStyle);
buttonTemplate.AddHandler(
Button.ClickEvent,
new RoutedEventHandler((o, e) => HandleColumnButtonClick(o, e))
);
DataGridTemplateColumn c = new DataGridTemplateColumn();
c.SortMemberPath = i.columnName;
c.CellTemplate=new DataTemplate() { VisualTree = buttonTemplate };
AddHeader(c,i);
return c;
}
Trying to replicate this using the RadGridView is giving me all sorts of problems, I think I'm going about it entirely wrong so I won't even post my failed attempts as I'm getting all sorts of bizarre errors.
How do I accomplish adding a button column dynamically in code to a RadGridView and setting it to my own event handler (there is an example on here but it's done in xaml and doesn't add an event handler for the button)?
Any help greatly appreciated.
I'm porting over working code that used the stock WPF DataGrid control. This is the method I *used* to use:
private DataGridTemplateColumn GetButtonColumn(IListPropertyInfo i)
{
var buttonTemplate = new FrameworkElementFactory(typeof(Button));
buttonTemplate.SetBinding(Button.ContentProperty, new Binding(i.columnName));
buttonTemplate.SetValue(Button.StyleProperty, DefaultStyles.GridColumnButtonStyle);
buttonTemplate.AddHandler(
Button.ClickEvent,
new RoutedEventHandler((o, e) => HandleColumnButtonClick(o, e))
);
DataGridTemplateColumn c = new DataGridTemplateColumn();
c.SortMemberPath = i.columnName;
c.CellTemplate=new DataTemplate() { VisualTree = buttonTemplate };
AddHeader(c,i);
return c;
}
Trying to replicate this using the RadGridView is giving me all sorts of problems, I think I'm going about it entirely wrong so I won't even post my failed attempts as I'm getting all sorts of bizarre errors.
How do I accomplish adding a button column dynamically in code to a RadGridView and setting it to my own event handler (there is an example on here but it's done in xaml and doesn't add an event handler for the button)?
Any help greatly appreciated.