MvvmCross 5.0.3-WPF-导航并返回结果

时间:2019-05-08 16:34:39

标签: wpf mvvmcross

我有一些问题可以理解,通过导航调用视图模型后是否可以等待答案。

我已经尝试升级MvvmCross版本,但是对于当前项目实际上是不可能的。我正在寻找解决方法(如果有)。

View MainView : MvxViewModel
public IMvxAsyncCommand ShowCommentPopup => new MvxAsyncCommand(() => ShowPopup());

private async Task ShowPopup() 
{
   var result = await _navigationService.Navigate<CommentViewModel, stringTitle, CommentResult>("comment below");
}

View CommentView : MvxViewModel<string, CommentResult>
public IMvxAsyncCommand CloseCommentPopup => new MvxAsyncCommand(() => ClosePopup());

private async Task ClosePopup()
{
   await _navigationService.Close(this);
}

public override Task Initialize(string parameter)
{
    _commentTitle = parameter;
    return base.Initialize();
}

WpfPresenter : MvxWpfViewPresenter
public override void Present(FrameworkElement frameworkElement)
{
    mainWindow.PresentInRegion(frameworkElement);
}
// If I override the "ChangePresentation" method, I am able to hide the active window.


MainWindow : Window
public void PresentInRegion(FrameworkElement frameworkElement)
{
    DataContext = frameworkElement.DataContext;
    Main.Children.Clear();
    Main.Children.Add(frameworkElement);
}

我想在适当的事件上关闭窗口,并将值返回给调用窗口的视图模型。

感谢您的提示。

请注意实际的界面(导航允许我们返回结果,而不是结束的。我知道以后的版本允许它,但是我需要找到该版本的解决方法)

public interface IMvxNavigationService
{
Task Navigate<TViewModel>() where TViewModel : IMvxViewModel;
Task Navigate<TViewModel, TParameter>(TParameter param) where TViewModel : IMvxViewModel;
Task<TResult> Navigate<TViewModel, TParameter, TResult>(TParameter param) where TViewModel : IMvxViewModel;
Task<TResult> Navigate<TViewModel, TResult>() where TViewModel : IMvxViewModel;
Task Navigate(string path);
Task Navigate<TParameter>(string path, TParameter param);
Task<TResult> Navigate<TResult>(string path);
Task<TResult> Navigate<TParameter, TResult>(string path, TParameter param);
Task<bool> CanNavigate<TViewModel>() where TViewModel : IMvxViewModel;
Task<bool> CanNavigate(string path);
Task<bool> Close(IMvxViewModel viewModel);
}

public static class MvxNavigationExtensions
{
public static Task<bool> CanNavigate(this IMvxNavigationService navigationService, Uri path)
public static Task Navigate(this IMvxNavigationService navigationService, Uri path)
public static Task Navigate<TParameter>(this IMvxNavigationService navigationService, Uri path, TParameter param)
public static Task<TResult> Navigate<TResult>(this IMvxNavigationService navigationService, Uri path)
public static Task<TResult> Navigate<TParameter, TResult>(this IMvxNavigationService navigationService, Uri path, TParameter param)
Task<bool> Close<TViewModel>(this IMvxNavigationService navigationService)
}

0 个答案:

没有答案