Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将匿名方法转换为类型';System.Windows.Threading.DispatcherPriority';因为它不是委托类型_C#_Wpf_Delegates - Fatal编程技术网

C# 无法将匿名方法转换为类型';System.Windows.Threading.DispatcherPriority';因为它不是委托类型

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

我想编译这个WPF代码并得到这个错误

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)  

抱歉,如果忘记将委托放入操作实例中