Exemplo n.º 1
0
 public async void ShowFlyoutView <TView>(
     ViewRequest viewRequest     = null,
     UiShowFlyoutOptions options = null)
     where TView : class, IView
 {
     await ShowFlyoutView <TView, Unit>();
 }
Exemplo n.º 2
0
 public Task <TResult> ShowFlyoutView <TView, TResult>(
     ViewRequest viewRequest     = null,
     UiShowFlyoutOptions options = null)
     where TView : class, IView
 {
     return(ShowFlyoutView <TResult>(
                container => container.Resolve <TView>(),
                viewRequest,
                options));
 }
Exemplo n.º 3
0
 public async void ShowFlyoutView(Func <ILifetimeScope, IView> viewFactory, ViewRequest viewRequest = null,
                                  UiShowFlyoutOptions options = null)
 {
     await ShowFlyoutView <Unit>(viewFactory, viewRequest, options);
 }
Exemplo n.º 4
0
        public async Task <TResult> ShowFlyoutView <TResult>(Func <ILifetimeScope, IView> viewFactory,
                                                             ViewRequest viewRequest = null, UiShowFlyoutOptions options = null)
        {
            if (!string.IsNullOrEmpty(viewRequest?.ViewId))
            {
                var viewOld = FlyoutsControl.Items
                              .Cast <Flyout>()
                              .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(default(TResult));
                }
            }

            var view = viewFactory(Container);

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

            options = options ?? new UiShowFlyoutOptions();

            var flyout = new Flyout
            {
                IsModal               = options.IsModal,
                Position              = options.Position,
                Theme                 = options.Theme,
                ExternalCloseButton   = options.ExternalCloseButton,
                IsPinned              = options.IsPinned,
                CloseButtonIsCancel   = options.CloseByEscape,
                CloseCommand          = options.CloseCommand,
                CloseCommandParameter = options.CloseCommandParameter,
                AnimateOpacity        = options.AnimateOpacity,
                AreAnimationsEnabled  = options.AreAnimationsEnabled,
                IsAutoCloseEnabled    = options.IsAutoCloseEnabled,
                AutoCloseInterval     = options.AutoCloseInterval,
                Width                 = options.Width ?? double.NaN,
                Height                = options.Height ?? double.NaN,
                Content               = view,
                IsOpen                = true
            };

            var vm = view.ViewModel as ViewModelBase;

            if (vm != null)
            {
                Observable
                .FromEventPattern <ViewModelCloseQueryArgs>(
                    x => vm.CloseQuery       += x,
                    x => vm.CloseQuery       -= x)
                .Subscribe(x => flyout.IsOpen = false)
                .DisposeWith(vm.Disposables);
            }

            var disposables = new CompositeDisposable();

            view.ViewModel
            .WhenAnyValue(x => x.Title)
            .Subscribe(x =>
            {
                flyout.Header          = x;
                flyout.TitleVisibility =
                    !string.IsNullOrEmpty(x)
                            ? Visibility.Visible
                            : Visibility.Collapsed;
            })
            .DisposeWith(disposables);
            view.ViewModel
            .WhenAnyValue(x => x.CanClose)
            .Subscribe(x => flyout.CloseButtonVisibility = x ? Visibility.Visible : Visibility.Collapsed)
            .DisposeWith(disposables);

            var closedObservable = Observable
                                   .FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                x => flyout.ClosingFinished += x,
                x => flyout.ClosingFinished -= x);

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

            await closedObservable.FirstAsync();

            disposables.Dispose();
            vm?.Closed(new ViewModelCloseQueryArgs());
            flyout.Content = null;
            FlyoutsControl.Items.Remove(flyout);

            if (vm is IResultableViewModel <TResult> model)
            {
                return(model.ViewResult);
            }

            return(default(TResult));
        }