C# 无法将匿名方法转换为类型';System.Windows.Threading.DispatcherPriority';因为它不是委托类型
我想编译这个WPF代码并得到这个错误C# 无法将匿名方法转换为类型';System.Windows.Threading.DispatcherPriority';因为它不是委托类型,c#,wpf,delegates,C#,Wpf,Delegates,我想编译这个WPF代码并得到这个错误 public void SetContentObject(Type contentType) { this.Dispatcher.BeginInvoke(delegate(Type input) //Error here <- { object obj = Activator.CreateInstance(input); th
public void SetContentObject(Type contentType)
{
this.Dispatcher.BeginInvoke(delegate(Type input) //Error here <-
{
object obj = Activator.CreateInstance(input);
this.Content = obj;//this.Content declared as object
}, new object[]
{
contentType
});
}
public void SetContentObject(类型contentType)
{
this.Dispatcher.BeginInvoke(delegate(Type input)//Error hereDispatcher.BeginInvoke()方法应在不带参数的情况下传递委托(请参阅)。您可以通过在anaimous方法之外声明参数来传递它。已更新
public void SetContentObject(Type contentType)
{
Type input;
Dispatcher.BeginInvoke(new Action(delegate
{
object obj = Activator.CreateInstance(input);
this.Content = obj;
}), new object[]
{
contentType
});
}
您可能会与Invoke和BeginInvoke混淆:
public void Invoke(Action callback, DispatcherPriority priority)
//no priority is allowed below.
public DispatcherOperation BeginInvoke(Action a)
抱歉,如果忘记将委托放入操作实例中