我有一个Controller类,它应该控制MainForm上对象的外观。
每当我尝试在我的Controller类中更改UserControl的属性(如此处的Opacity)时,它都会失败并显示InvalidOperationException
编辑:这是整个错误消息:
WindowsBase.dll中出现'System.InvalidOperationException'类型的异常,但未在用户代码中处理 调用线程无法访问此对象,因为另一个线程拥有它
public partial class MainWindow : Window
{
private CubeControl _cube; //derived from System.Windows.Control.UserControl
private CubeController _cubeController;
public MainWindow()
{
InitializeComponent();
_cubeController = new CubeController(_cube);
}
}
这是Controller-class
public class CubeController
{
/// <summary>A reference to the main cube control</summary>
private CubeControl _cubeControl;
public CubeController(CubeControl cubeControl)
{
_cubeControl = cubeControl;
// this fails with an InvalidOperationException
_cubeControl.Opacity = 0.3;
}
我做错了什么?