添加图像/按钮在C#Silverlight中动态单击事件处理程序

时间:2010-07-08 15:02:01

标签: c#

请检查以下内容:

/// <summary>
/// This method returns a custom column control for the AgDataGrid from devex with a   button design including button click event handlers
/// </summary>
/// <param name="headerContent">The header column value for this cell</param>
/// <param name="control">The DataTemplate XAML needed to Load the control</param>
/// <param name="routedEventHandler">The Button Click Event</param>
/// <returns>AgDataGridColumn</returns>
public AgDataGridColumn CustomColumn(string headerContent, string control, RoutedEventHandler routedEventHandler)
{
AgDataGridColumn _AgDataGridColumn = new AgDataGridColumn();
_AgDataGridColumn.HeaderContent = headerContent;
_AgDataGridColumn.CellDisplayTemplate = XamlReader.Load(control) as DataTemplate;
_AgDataGridColumn.AllowSorting = DefaultBoolean.False;
_AgDataGridColumn.PrepareCellDisplayElement += (d, _e) =>
{
    ((Button)_e.DisplayElement).Click -= routedEventHandler;
    ((Button)_e.DisplayElement).Click += routedEventHandler;
};
return (_AgDataGridColumn);
}

我想将此方法转换为silverlight数据网格。我正在尝试找到一个正确的方法来执行PrepareCellDisplayElement行,添加事件处理程序。 sl datagrid似乎不存在该方法。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

可以在@ http://forums.silverlight.net/forums/p/189927/440746.aspx找到一个解决方案。不幸的是,我不喜欢在每个数据行加载上附加click事件处理程序的想法。