Catel.Services.UIVisualizerService.ShowAsync C# (CSharp) Method

ShowAsync() public method

Shows a window that is registered with the specified view model in a non-modal state.
The is null. /// The is not registered by the /// method first. ///
public ShowAsync ( IViewModel viewModel, EventHandler completedProc = null ) : Task
viewModel IViewModel The view model.
completedProc EventHandler /// The callback procedure that will be invoked as soon as the window is closed. This value can /// be null. ///
return Task
        public async Task<bool?> ShowAsync(IViewModel viewModel, EventHandler<UICompletedEventArgs> completedProc = null)
        {
            Argument.IsNotNull(() => viewModel);

            bool? result = null;
            var viewModelType = viewModel.GetType();
            var resolvedView = _viewLocator.ResolveView(viewModelType);
            var view = (View) _typeFactory.CreateInstance(resolvedView);

            if (view is IView)
            {
                (view as IView).DataContext = viewModel;
            }
            else
            {
                view.BindingContext = viewModel;
            }

            var okButton = new Button
            {
                Text = _languageService.GetString("OK")
            };

            okButton.Clicked += async (sender, args) =>
            {
                result = true;
                OnOkButtonClicked(viewModel, completedProc);
            };

            var cancelButton = new Button
            {
                Text = _languageService.GetString("Cancel")
            };

            cancelButton.Clicked += async (sender, args) =>
            {
                result = false;
                OnCancelButtonClicked(viewModel, completedProc);
            };

            var dataErrorInfo = viewModel as INotifyDataErrorInfo;
            if (dataErrorInfo != null)
            {
                Action checkIfViewModelHasErrors = () => okButton.IsEnabled = !dataErrorInfo.HasErrors;
                viewModel.PropertyChanged += (sender, args) => checkIfViewModelHasErrors();
                checkIfViewModelHasErrors();
            }

            ////TODO: Improve the layout.
            var buttonsStackLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center
            };

            buttonsStackLayout.Children.Add(okButton);
            buttonsStackLayout.Children.Add(cancelButton);

            var contentLayout = new StackLayout();
            contentLayout.Children.Add(view);
            contentLayout.Children.Add(buttonsStackLayout);

            if (!await TryDisplayAsPopup(viewModel, completedProc, contentLayout))
            {
                await DisplayUsingNavigation(viewModel, completedProc, contentLayout);
            }

            return result;
        }

Same methods

UIVisualizerService::ShowAsync ( string name, object data, EventHandler completedProc = null ) : Task