无法将 lambda 表达式转换为类型“System.Delegate”,因为它不是 wpf 中的委托类型
本文关键字:类型 因为 wpf Delegate 表达式 lambda 转换 System | 更新日期: 2023-09-27 18:21:27
public void loadtemplist(DataTable dt)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
(Delegate) (() => this.loadtemplist1(dt)) //error
);
}
和
public void loadtemplist1(DataTable dt)
{
-----
-----
}
上面的代码抛出 无法将lambda表达式转换为类型"System.Delegate",因为它不是委托类型
您不能将匿名方法直接转换为System.Delegate
- 您需要先将其包装在Action
中。
试试这个:
public void loadtemplist(DataTable dt)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
new Action(() => { this.loadtemplist1(dt); } )
);
}
你应该这样做
this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
new Action(() => this.loadtemplist1(dt)) );
查看演示:https://dotnetfiddle.net/nz9xxD