SilverLight 4,DataGrid,DataGridColumnHeader,MouseLeftButtonDown事件

时间:2012-03-31 17:03:20

标签: silverlight datagrid mouseleftbuttondown datagridcolumnheader

DataGridColumnHeader有事件MouseLeftButtonDown。我该如何使用此活动?

如何使用DataGridColumn加入DataGridColumnHeader?

for Example:
...
  DataGridTextColumn TC;
  TC = new DataGridTextColumn();
  TC.Header = "ID";
  TC.Binding = new Binding();
  TC.Binding.Converter = new MyCustomConverter();
  TC.Binding.ConverterParameter = 0;

  // I need something like this:
  TC.MouseLeftButtonDown += new event .... 
  // i need - when click on column header, my custom function will executed.

  dataGrid.Columns.Add( TC );

1 个答案:

答案 0 :(得分:0)

我见过最糟糕的代码;)sry 你应该使用一个方法(回调)/ lambda确保满足事件委托签名来处理事件

回调方法:

TC.MouseLeftButtonDown += MouseLeftButtonDownHandler;
//define callback
private void MouseLeftButtonDownHandler(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
    //write ur logic here...
}

Lambda方法

TC.MouseLeftButtonDown += (sender, args) => {//write ur logic here}
//where "sender" means the object raises the event(i.e. "TC"), args - object contains some helpfull information about the happened event(like "ClickCount", etc.).

此链接非常有用:

Delegates

Events