Exemplo n.º 1
0
 public void ShowChildWindowView <TView>(
     ViewRequest viewRequest          = null,
     UiShowChildWindowOptions options = null)
     where TView : class, IView
 {
     ShowChildWindowView <TView, Unit>();
 }
Exemplo n.º 2
0
        public RecepientManagerViewModel(ICachedService cachedService, IShell shell)
        {
            CanClose           = false;
            this.cachedService = cachedService;
            Shell = shell as CachedServiceShell;

            var editorOptions = new UiShowChildWindowOptions
            {
                IsModal      = true,
                AllowMove    = true,
                CanClose     = true,
                ShowTitleBar = true,
                Title        = "Recepient group editing"
            };

            CreateGroupCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                await Shell.ShowChildWindowView <RecepientEditorView, Unit>(
                    new RecepientEditorRequest
                {
                    Group = new ApiRecepientGroup()
                },
                    editorOptions);
            }, Shell.CanEdit);

            EditGroupCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                await Shell.ShowChildWindowView <RecepientEditorView, Unit>(
                    new RecepientEditorRequest
                {
                    Group = SelectedGroup
                },
                    editorOptions);
            }, Shell.CanEdit);
        }
Exemplo n.º 3
0
 public Task <TResult> ShowChildWindowView <TView, TResult>(
     ViewRequest viewRequest          = null,
     UiShowChildWindowOptions options = null)
     where TView : class, IView
 {
     return(ShowChildWindowView <TResult>(
                container => container.Resolve <TView>(),
                viewRequest,
                options));
 }
        private async Task SelectOperFromTemplates()
        {
            var editorOptions = new UiShowChildWindowOptions
            {
                IsModal      = true,
                AllowMove    = true,
                CanClose     = true,
                ShowTitleBar = true,
                Title        = "Select operation template",
                Width        = 700
            };

            await Shell.ShowChildWindowView <OperTemplatesListView, Unit>(
                new OperTemplatesListRequest
                { TaskEditor = this },
                editorOptions);
        }
Exemplo n.º 5
0
 public ChildWindowView(UiShowChildWindowOptions options)
 {
     DataContext = options;
     InitializeComponent();
 }
Exemplo n.º 6
0
 public async void ShowChildWindowView(Func <ILifetimeScope, IView> viewFactory, ViewRequest viewRequest = null,
                                       UiShowChildWindowOptions options = null)
 {
     await ShowChildWindowView <Unit>(viewFactory, viewRequest, options);
 }
Exemplo n.º 7
0
        public Task <TResult> ShowChildWindowView <TResult>(Func <ILifetimeScope, IView> viewFactory,
                                                            ViewRequest viewRequest          = null,
                                                            UiShowChildWindowOptions options = null)
        {
            if (!string.IsNullOrEmpty(viewRequest?.ViewId))
            {
                var metroDialogContainer = Window.Template.FindName("PART_MetroActiveDialogContainer", Window) as Grid;
                metroDialogContainer = metroDialogContainer ??
                                       Window.Template.FindName("PART_MetroInactiveDialogsContainer", Window) as Grid;

                if (metroDialogContainer == null)
                {
                    throw new InvalidOperationException(
                              "The provided child window can not add, there is no container defined.");
                }

                var viewOld = metroDialogContainer.Children
                              .Cast <ChildWindowView>()
                              .Select(x => (IView)x.Content)
                              .FirstOrDefault(x => (x.ViewModel as ViewModelBase)?.ViewId == viewRequest.ViewId);

                if (viewOld != null)
                {
                    (viewOld.ViewModel as Ui.Wpf.Common.ViewModels.IActivatableViewModel)?.Activate(viewRequest);
                    return(Task.FromResult(default(TResult)));
                }
            }

            var view = viewFactory(Container);

            if (options != null)
            {
                view.Configure(options);
            }

            InitializeView(view, viewRequest);
            (view.ViewModel as Ui.Wpf.Common.ViewModels.IActivatableViewModel)?.Activate(viewRequest);

            options = options ?? new UiShowChildWindowOptions();

            var childWindow = new ChildWindowView(options)
            {
                Content = view
            };

            var vm = view.ViewModel as ViewModelBase;

            if (vm != null)
            {
                Observable
                .FromEventPattern <ViewModelCloseQueryArgs>(
                    x => vm.CloseQuery += x,
                    x => vm.CloseQuery -= x)
                .Subscribe(x =>
                {
                    if (vm is IResultableViewModel <TResult> model)
                    {
                        childWindow.Close(model.ViewResult);
                    }
                    else
                    {
                        childWindow.Close();
                    }
                })
                .DisposeWith(vm.Disposables);

                Observable
                .FromEventPattern <CancelEventArgs>(
                    x => childWindow.Closing += x,
                    x => childWindow.Closing -= x)
                .Subscribe(x =>
                {
                    var vcq = new ViewModelCloseQueryArgs {
                        IsCanceled = false
                    };
                    vm.Closing(vcq);

                    if (vcq.IsCanceled)
                    {
                        x.EventArgs.Cancel = true;
                    }
                })
                .DisposeWith(vm.Disposables);
            }

            var disposables = new CompositeDisposable();

            view.ViewModel
            .WhenAnyValue(x => x.Title)
            .Subscribe(x => childWindow.Title = x)
            .DisposeWith(disposables);
            view.ViewModel
            .WhenAnyValue(x => x.CanClose)
            .Subscribe(x => childWindow.ShowCloseButton = x)
            .DisposeWith(disposables);

            Observable
            .FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                x => childWindow.ClosingFinished += x,
                x => childWindow.ClosingFinished -= x)
            .Select(x => (ChildWindow)x.Sender)
            .Take(1)
            .Subscribe(x =>
            {
                disposables.Dispose();
                vm?.Closed(new ViewModelCloseQueryArgs());
                x.Content = null;
            });

            return(Window.ShowChildWindowAsync <TResult>(
                       childWindow,
                       options.OverlayFillBehavior
                       ));
        }