[英]Delegate won't update page
I am trying to change the active index of a multiview by using a delegate and it doesn't work as i expect. 我正在尝试通过使用委托来更改多视图的活动索引,但它没有按我期望的那样工作。
this is my code 这是我的代码
protected void ucWaitPage_FinishedWaiting(PerformAfterWaitDelegate performAfterWait)
{
performAfterWait.Invoke();
this.SetIndex();
}
private void SetIndex()
{
this.mvwTest.ActiveViewIndex = 0;
}
The performAfterWait Delegate points to the SetIndex() method. performAfterWait委托指向SetIndex()方法。
When the performAfterWait delegate gets invoked SetIndex() gets called but when SetIndex() returns this.mvwTest.ActiveViewIndex reverts to being equal to 1. 当performAfterWait委托被调用时,SetIndex()被调用,但是SetIndex()返回this.mvwTest.ActiveViewIndex恢复为等于1。
However when i call the SetIndex() method directly it sets this.mvwTest.ActiveViewIndex = 0 and the change persists when the method returns. 但是,当我直接调用SetIndex()方法时,它将设置this.mvwTest.ActiveViewIndex = 0,并且该方法返回时更改仍然存在。
When the performAfterWait delegate gets invoked SetIndex() gets called but when SetIndex() returns this.mvwTest.ActiveViewIndex reverts to being equal to 1.
当performAfterWait委托被调用时,SetIndex()被调用,但是SetIndex()返回this.mvwTest.ActiveViewIndex恢复为等于1。
How do you verify this, can you put Debug.WriteLine(this.mvwTest.ActiveViewIndex) after the invoke function? 如何验证这一点,能否将Debug.WriteLine(this.mvwTest.ActiveViewIndex)放在调用函数之后?
By the way, what do you want to use invoke to call that method? 顺便说一句,您要使用invoke调用该方法什么? Do you just want to test the delegate.
您是否只想测试委托。 I don't see the advantage if you are still calling from the same thread.
如果您仍从同一线程进行调用,我看不出有什么好处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.