
[英]Caliburn.Micro - How to ActivateItem from class other than the Conductor
[英]Action after ActivateItem in Caliburn.Micro
我有个问题。 我在启动ActivateItem
位置有一个按钮:
public void LoadTaskManagerPage()
{
this.ActivateItem(new TaskManagerViewModel(this.LoggedUser, this.repository));
if (this.LoggedUser.GetUserTask() != null)
{
this.IsActiveTaskButtonVisible = Visibility.Visible;
this.NotifyOfPropertyChange(() => this.IsActiveTaskButtonVisible);
}
}
如果ActivateItem
结束,是否可以hang
应用程序并转到if
语句?
如何在Caliburn.Micro中等待ActivateItem
结束?
编辑:
尝试类似的东西:
public void LoadTaskManagerPage()
{
var taskManagerTask = Task.Run(() => this.ActivateItem(new TaskManagerViewModel(this.LoggedUser, this.repository)));
taskManagerTask.Wait();
if (!this.LoggedUser.GetUserTask().IsTaskTakenByUser())
{
this.IsActiveTaskButtonVisible = Visibility.Visible;
this.NotifyOfPropertyChange(() => this.IsActiveTaskButtonVisible);
}
}
使用Tasks,但是当我单击LoadTaskManagerPage()
它不会显示任何窗口,应用程序将永远挂起
编辑2
根据我在github上的问题 ,我将Caliburn升级到了alpha 4.0
:
public void LoadTaskManagerPage()
{
this.ActivateItemAsync(new TaskManagerViewModel(this.LoggedUser, this.repository));
if (!this.LoggedUser.GetUserTask().IsTaskTakenByUser())
{
//logic
}
}
我将ActiveItem()
更改为ActiveItemAsync()
但仍然击中if
语句,而活动项将关闭。 使用async/await
做同样的事情
编辑3
当我进行async/await
它仍然可以正常工作,请查看右侧的视图。 单击它, User Control
不会出现。 在同一时间(即使我的User Control
未显示),im命中if
语句也为时过早。 我想在User Control
关闭时将其选中。
您应该等待ActivateItemAsync
方法。 这意味着您的LoadTaskManagerPage()
应该返回一个Task
并且您也应该await
它:
public async Task LoadTaskManagerPageAsynnc()
{
await this.ActivateItemAsync(new TaskManagerViewModel(this.LoggedUser, this.repository));
if (!this.LoggedUser.GetUserTask().IsTaskTakenByUser())
{
//logic
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.