';System.Reflection.TargetParameterCountException';在wp

本文关键字:wp System Reflection TargetParameterCountException | 更新日期: 2023-09-27 18:00:04

当我尝试将UI更改为我的wpf应用程序时,由于发生了更改,我一直收到该异常

private delegate void MyFunctionDelegate2(double t1, double t2, double t3);
public void translate(double tx, double ty, double tz)
{
    Transform3DGroup transform = new Transform3DGroup();
    TranslateTransform3D t = new TranslateTransform3D(tx, ty, tz);
    transform.Children.Add(t);
    if (!Application.Current.Dispatcher.CheckAccess())
    {
        var objj = new MyFunctionDelegate2(translate);
        Application.Current.Dispatcher.BeginInvoke(objj);
    }
}

';System.Reflection.TargetParameterCountException';在wp

您没有在BeginInvoke调用中将这三个参数传递给MyFunctionDelegate2。它应该是这样的:

private delegate void MyFunctionDelegate2(double t1, double t2, double t3);
public void translate(double tx, double ty, double tz)
{
    if (!Application.Current.Dispatcher.CheckAccess())
    {
        var t = new MyFunctionDelegate2(translate);
        Application.Current.Dispatcher.BeginInvoke(t, tx, ty, tz);
    }
    else
    {
        var transform = new Transform3DGroup();
        var t = new TranslateTransform3D(tx, ty, tz);
        transform.Children.Add(t);
    }
}

或者更简单,没有委托声明:

public void translate(double tx, double ty, double tz)
{
    if (!Application.Current.Dispatcher.CheckAccess())
    {
        Application.Current.Dispatcher.BeginInvoke(
            new Action(() => translate(tx, ty, tz)));
    }
    else
    {
        Transform3DGroup transform = new Transform3DGroup();
        TranslateTransform3D t = new TranslateTransform3D(tx, ty, tz);
        transform.Children.Add(t);
    }
}