public virtual async Task LinkNew_CommandAsync(IAsyncView tgtView, IAsyncView curView, CancellationToken token = default) { NameValueCollection query = LinkNew_Params(); ViewModel tgtModel = ServiceProvider.GetService <SalesOrderViewModel>(); await NavigateToAsync(tgtModel, tgtView, query, this, curView, token); }
/// <summary> /// Asynchronous routine to activate a view model with given parameters either as a child or as standalone /// and display it in a new view or an existing view, which will need to be successfully closed first. /// </summary> /// <param name="tgtViewModel">View model to activate</param> /// <param name="tgtView">View to bind to the model</param> /// <param name="activationParams">A collection of activation parameters</param> /// <param name="srcViewModel">Parent model, or null if activate as standalone</param> /// <param name="curView">Optional current view to be replaced by the target view. Same as tgtView if we need to reuse the target view</param> /// <param name="token">Cancellation token.</param> /// <returns>True if navigation succeeded, false otherwise</returns> public static async Task <bool> NavigateToAsync(ViewModel tgtViewModel, IAsyncView tgtView, NameValueCollection activationParams, ViewModel srcViewModel, IAsyncView curView, CancellationToken token = default) { if (tgtViewModel == null || tgtView == null || curView != null && !(await curView.CanCloseAsync(token))) { return(false); } if (srcViewModel != null) { srcViewModel.SubscribeToChildEvents(tgtViewModel); } if (!(await tgtViewModel.ActivateAsync(activationParams, token)) && srcViewModel != null) { return(false); // child model activation reports showing view is not needed } if (curView != null) { // close the current view, or dispose if reusing it if (curView != tgtView) { await curView.CloseAsync(token); } else { await curView.DisposeAsync(token); } } tgtView.BindTo(tgtViewModel); await tgtView.ShowAsync(token); // always show even for the same view, in case mode has changed await tgtViewModel.FireEventAsync(ViewEvent.Opened); return(true); }