当我尝试将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);
}
}
答案 0 :(得分:0)
您没有在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);
}
}