示例#1
0
        public async Task <T> ShowDialogAsync <T>(DialogScreen <T> dialogScreen)
        {
            var view = GetViewForDialogScreen(dialogScreen);

            void OnDialogOpened(object?openSender, DialogOpenedEventArgs openArgs)
            {
                void OnScreenClosed(object?closeSender, EventArgs args)
                {
                    openArgs.Session.Close();
                    dialogScreen.Closed -= OnScreenClosed;
                }

                dialogScreen.Closed += OnScreenClosed;
            }

            await DialogHost.Show(view, OnDialogOpened);

            return(dialogScreen.DialogResult);
        }
示例#2
0
        public async Task <T> ShowDialogAsync <T>(DialogScreen <T> dialogScreen)
        {
            // Get the view that renders this viewmodel
            var view = _viewManager.CreateAndBindViewForModelIfNecessary(dialogScreen);

            // Set up event routing that will close the view when called from viewmodel
            DialogOpenedEventHandler onDialogOpened = (sender, e) =>
            {
                // Delegate to close the dialog and unregister event handler
                void OnScreenClosed(object o, CloseEventArgs args)
                {
                    e.Session.Close();
                    dialogScreen.Closed -= OnScreenClosed;
                }

                dialogScreen.Closed += OnScreenClosed;
            };

            // Show view
            await DialogHost.Show(view, onDialogOpened);

            // Return the result
            return(dialogScreen.DialogResult);
        }
示例#3
0
        public UIElement GetViewForDialogScreen <T>(DialogScreen <T> dialogScreen)
        {
            var dialogScreenType = dialogScreen.GetType();

            if (_dialogScreenViewCache.TryGetValue(dialogScreenType, out var cachedView))
            {
                _viewManager.BindViewToModel(cachedView, dialogScreen);
                return(cachedView);
            }
            else
            {
                var view = _viewManager.CreateAndBindViewForModelIfNecessary(dialogScreen);

                // This warms up the view and triggers all bindings.
                // We need to do this, as the view may have nested model-bound ContentControls
                // which take a very long time to load.
                // By pre-loading them as early as possible, we avoid doing it when the dialog
                // actually pops up, which improves user experience.
                // Ideally, the whole view cache should be populated at application startup.
                view.Arrange(new Rect(0, 0, 500, 500));

                return(_dialogScreenViewCache[dialogScreenType] = view);
            }
        }