コード例 #1
0
        /// <summary>
        /// Shows dialog as an asynchronous operation.
        /// </summary>
        /// <typeparam name="TEntity">The type of the t entity.</typeparam>
        /// <param name="dialog">The dialog.</param>
        /// <param name="viewmodel">The viewmodel.</param>
        private async Task CreateDialogAsync <TEntity>(Window dialog, IViewModelDialog <TEntity> viewmodel)
        {
            if (Application.Current is BaseApplication baseApplication)
            {
                dialog.XamlRoot = baseApplication.MainWindow.Content.XamlRoot;
            }

            dialog.DataContext = viewmodel;

            dialog.PrimaryButtonCommand   = viewmodel.Submit_Command;
            dialog.SecondaryButtonCommand = viewmodel.Close_Command;
            dialog.CloseButtonCommand     = viewmodel.Close_Command;

            dialog.PrimaryButtonStyle   = (Style)Application.Current.Resources["DefaultDialogButtonStyle"];
            dialog.SecondaryButtonStyle = (Style)Application.Current.Resources["DefaultDialogButtonStyle"];
            dialog.CloseButtonStyle     = (Style)Application.Current.Resources["DefaultDialogButtonStyle"];

            viewmodel.Submitted += (sender, e) => CloseDialog(dialog);
            viewmodel.Cancelled += (sender, e) => CloseDialog(dialog);
            viewmodel.Closed    += (sender, e) => CloseDialog(dialog);

            if (!viewmodel.IsInitialized)
            {
                await viewmodel.InitializeAsync();
            }

            await OpenDialogAsync(dialog);
        }
コード例 #2
0
ファイル: WindowFactory.cs プロジェクト: jorgemvc/CQRS.WPF
 public override Window BuildNewWindow(IViewModelDialog viewModel)
 {
     if (viewModel is CreateNewOrderViewModel)
     {
         return(new CreateNewOrderView());
     }
     return(base.BuildNewWindow(viewModel));
 }
コード例 #3
0
        // ----- Private methods.
        private void OpenDialogWith(IViewModelDialog viewModel)
        {
            var window = ViewFactory.BuildNewWindow(viewModel);

            window.DataContext = viewModel;
            window.Closed     += (sender, args) => { viewModel.IsVisible = false; };
            _window            = window;
            window.ShowDialog();
        }
コード例 #4
0
        /// <summary>
        /// Shows the dialog asynchronous.
        /// </summary>
        /// <typeparam name="TWindow">The type of the t window.</typeparam>
        /// <typeparam name="TViewModel">The type of the t view model.</typeparam>
        /// <typeparam name="TEntity">The type of the t entity.</typeparam>
        /// <param name="viewmodel">The viewmodel.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public Task ShowDialogAsync <TWindow, TViewModel, TEntity>(IViewModelDialog <TEntity> viewmodel = null)
            where TWindow : IWindow
            where TViewModel : IViewModelDialog <TEntity>
        {
            if (viewmodel is null)
            {
                viewmodel = (IViewModelDialog <TEntity>)ServiceLocator.Default.GetInstance(typeof(TViewModel));
            }

            return(CreateDialogAsync((System.Windows.Window)ServiceLocator.Default.GetInstance(typeof(TWindow)), viewmodel));
        }
コード例 #5
0
 private void ViewModelOnVisibilityChanged(IViewModelDialog viewModel)
 {
     if (viewModel.IsVisible)
     {
         OpenDialogWith(viewModel);
     }
     else
     {
         CloseCurrentWindow();
     }
 }
コード例 #6
0
        /// <summary>
        /// Shows dialog as an asynchronous operation.
        /// </summary>
        /// <typeparam name="TEntity">The type of the t entity.</typeparam>
        /// <param name="dialog">The dialog.</param>
        /// <param name="viewmodel">The viewmodel.</param>
        private async Task CreateDialogAsync <TEntity>(System.Windows.Window dialog, IViewModelDialog <TEntity> viewmodel)
        {
            dialog.DataContext = viewmodel;

            viewmodel.Submitted += (sender, e) => CloseDialog(dialog);
            viewmodel.Cancelled += (sender, e) => CloseDialog(dialog);
            viewmodel.Closed    += (sender, e) => CloseDialog(dialog);

            if (!viewmodel.IsInitialized)
            {
                await viewmodel.InitializeAsync();
            }

            await OpenDialogAsync(dialog);
        }
コード例 #7
0
        public async Task <DialogResultEnum> ShowView(IViewModelDialog viewModel)
        {
            var dialogResult         = DialogResultEnum.NotSet;
            var taskCompletionSource = new TaskCompletionSource <object>();
            var page = new ContentPage();

            page.BindingContext = viewModel;
            page.Title          = viewModel.PageTitle;
            ContentView contentView;
            Type        viewType;

            if (_mappings.TryGetValue(viewModel.GetType(), out viewType))
            {
                contentView = Activator.CreateInstance(viewType) as ContentView;
                if (contentView != null)
                {
                    page.Content = contentView;
                }
            }

            viewModel.RequestClose = async(result) => {
                dialogResult = result;
                await _mainPage.Navigation.PopAsync();
            };

            page.Disappearing += (s, e) => {
                if (dialogResult == DialogResultEnum.NotSet)
                {
                    dialogResult = DialogResultEnum.Back;
                }
                taskCompletionSource.SetResult(null);
            };

            await _mainPage.Navigation.PushAsync(page);

            await taskCompletionSource.Task;

            return(dialogResult);
        }
コード例 #8
0
 public ViewModelChangedEventArgs(IViewModelDialog oldViewModel, IViewModelDialog newViewModel)
 {
     OldViewModel = oldViewModel;
     NewViewModel = newViewModel;
 }
コード例 #9
0
 public virtual Window BuildNewWindow(IViewModelDialog viewModel)
 {
     return(new Window());
 }
コード例 #10
0
 /// <summary>
 /// Shows the dialog asynchronous.
 /// </summary>
 /// <typeparam name="TEntity">The type of the t entity.</typeparam>
 /// <param name="type">The type.</param>
 /// <param name="viewmodel">The viewmodel.</param>
 /// <returns>Task&lt;System.Boolean&gt;.</returns>
 public Task ShowDialogAsync <TEntity>(Type type, IViewModelDialog <TEntity> viewmodel) =>
 CreateDialogAsync((System.Windows.Window)ServiceLocator.Default.GetInstance(type), viewmodel);
コード例 #11
0
 /// <summary>
 /// Shows the dialog asynchronous.
 /// </summary>
 /// <typeparam name="TEntity">The type of the t entity.</typeparam>
 /// <param name="window">The window.</param>
 /// <param name="viewmodel">The viewmodel.</param>
 /// <returns>Task&lt;System.Boolean&gt;.</returns>
 public Task ShowDialogAsync <TEntity>(IWindow window, IViewModelDialog <TEntity> viewmodel) =>
 CreateDialogAsync((Window)ServiceLocator.Default.GetInstance(window.GetType()), viewmodel);