/// <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); }
public override Window BuildNewWindow(IViewModelDialog viewModel) { if (viewModel is CreateNewOrderViewModel) { return(new CreateNewOrderView()); } return(base.BuildNewWindow(viewModel)); }
// ----- 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(); }
/// <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<System.Boolean>.</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)); }
private void ViewModelOnVisibilityChanged(IViewModelDialog viewModel) { if (viewModel.IsVisible) { OpenDialogWith(viewModel); } else { CloseCurrentWindow(); } }
/// <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); }
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); }
public ViewModelChangedEventArgs(IViewModelDialog oldViewModel, IViewModelDialog newViewModel) { OldViewModel = oldViewModel; NewViewModel = newViewModel; }
public virtual Window BuildNewWindow(IViewModelDialog viewModel) { return(new Window()); }
/// <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<System.Boolean>.</returns> public Task ShowDialogAsync <TEntity>(Type type, IViewModelDialog <TEntity> viewmodel) => CreateDialogAsync((System.Windows.Window)ServiceLocator.Default.GetInstance(type), viewmodel);
/// <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<System.Boolean>.</returns> public Task ShowDialogAsync <TEntity>(IWindow window, IViewModelDialog <TEntity> viewmodel) => CreateDialogAsync((Window)ServiceLocator.Default.GetInstance(window.GetType()), viewmodel);