我正在使用我创建的自定义附加事件,我正在尝试向该事件添加处理程序
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void dataGridTasks_Drop(object sender, RoutedEventArgs e)
{
}
}
这里是 XAML 代码
<ListView util:DragDropHelper.Drop="dataGridTasks_Drop">
我在 InitializeComponent 的运行时出现此错误
“System.String”类型的对象无法转换为“System.Windows.RoutedEventHandler”类型。
任何人都知道我为什么会收到这个错误?谢谢 !
这是我的事件代码
public static readonly RoutedEvent DropEvent = EventManager.RegisterRoutedEvent(
"Drop", RoutingStrategy.Bubble, typeof(DropEventArgs), typeof(DragDropHelper));
public static void AddDropHandler(DependencyObject d, RoutedEventHandler handler)
{
UIElement uie = d as UIElement;
if (uie != null)
{
uie.AddHandler(DragDropHelper.DropEvent, handler);
}
}
public static void RemoveDropHandler(DependencyObject d, RoutedEventHandler handler)
{
UIElement uie = d as UIElement;
if (uie != null)
{
uie.RemoveHandler(DragDropHelper.DropEvent, handler);
}
}
DropEventArgs 代码
class DropEventArgs : RoutedEventArgs
{
public object Data { get; private set; }
public int Index { get; private set; }
public DropEventArgs(RoutedEvent routedEvent, object data, int index)
: base(routedEvent)
{
Data = data;
Index = index;
}
}