예제 #1
0
        public async Task BackButtonExecutesCommand()
        {
            var       pushedPage = new ContentPage();
            TestShell testShell  = new TestShell(new ContentPage());
            var       window     = new Window()
            {
                Page = testShell
            };

            bool   commandExecuted = false;
            string parameter       = String.Empty;
            var    command         = new Command((p) =>
            {
                parameter       = $"{p}";
                commandExecuted = true;
            });

            var backButtonBehavior = new BackButtonBehavior()
            {
                Command          = command,
                CommandParameter = "PARAMETER"
            };

            await testShell.Navigation.PushAsync(pushedPage);

            Shell.SetBackButtonBehavior(pushedPage, backButtonBehavior);

            (window as IWindow).BackButtonClicked();

            // Validate that we didn't navigate back and only the
            // Command was executed
            Assert.AreEqual(pushedPage, testShell.CurrentPage);
            Assert.IsTrue(commandExecuted);
            Assert.AreEqual("PARAMETER", parameter);
        }
예제 #2
0
파일: ShellTests.cs 프로젝트: AswinPG/maui
        public async Task SetHasBackButton()
        {
            SetupBuilder();

            var shell = await InvokeOnMainThreadAsync <Shell>(() =>
            {
                return(new Shell()
                {
                    Items = { new ContentPage() }
                });
            });

            await CreateHandlerAndAddToWindow <ShellHandler>(shell, async (handler) =>
            {
                Assert.False(IsBackButtonVisible(shell.Handler));
                await shell.Navigation.PushAsync(new ContentPage());
                Assert.True(IsBackButtonVisible(shell.Handler));

                BackButtonBehavior behavior = new BackButtonBehavior()
                {
                    IsVisible = false
                };

                Shell.SetBackButtonBehavior(shell.CurrentPage, behavior);
                Assert.False(IsBackButtonVisible(shell.Handler));
                behavior.IsVisible = true;
                NavigationPage.SetHasBackButton(shell.CurrentPage, true);
            });
        }
예제 #3
0
        protected override void Init()
        {
            _behavior = new BackButtonBehavior();
            var page = GetContentPage(title);

            Shell.SetBackButtonBehavior(page, _behavior);
            AddContentPage(page).Title = title;
        }
예제 #4
0
        public OrderPageViewModel()
        {
            Console.WriteLine("Created new OrderPage");
            Title      = "Your order";
            backButton = new BackButtonBehavior();

            //Customers = sipItService.GetCustomers();
        }
예제 #5
0
        protected override void Init()
        {
            _behavior = new BackButtonBehavior();
            var page = GetContentPage(title);

            Shell.SetBackButtonBehavior(page, _behavior);
            AddContentPage(page).Title = FlyoutItem;
            Shell.SetFlyoutBehavior(this.CurrentItem, FlyoutBehavior.Disabled);
        }
예제 #6
0
        public void BackButtonBehaviorBindingContextPropagationWithExistingBindingContext()
        {
            object bindingContext     = new object();
            var    page               = new ContentPage();
            var    backButtonBehavior = new BackButtonBehavior();

            page.BindingContext = bindingContext;
            Shell.SetBackButtonBehavior(page, backButtonBehavior);

            Assert.AreEqual(page.BindingContext, backButtonBehavior.BindingContext);
        }
예제 #7
0
        public void BackButtonBehaviorSet()
        {
            var page = new ContentPage();

            Assert.IsNull(Shell.GetBackButtonBehavior(page));

            var backButtonBehavior = new BackButtonBehavior();

            Shell.SetBackButtonBehavior(page, backButtonBehavior);

            Assert.AreEqual(backButtonBehavior, Shell.GetBackButtonBehavior(page));
        }
		void OnBackButtonCommandCanExecuteChanged(object sender, EventArgs e)
		{
			if (NavigationItem?.LeftBarButtonItem == null)
				return;

			bool isEnabled = BackButtonBehavior.GetPropertyIfSet<bool>(BackButtonBehavior.IsEnabledProperty, true);

			if (isEnabled && sender is ICommand command)
				isEnabled = command.CanExecute(BackButtonBehavior?.CommandParameter);

			NavigationItem.LeftBarButtonItem.Enabled = isEnabled;
		}
            void ToggleFlyoutBehavior(object obj)
            {
                var behavior = (int)(Shell.Current.FlyoutBehavior);

                behavior++;

                if (Enum.GetValues(typeof(FlyoutBehavior)).Length <= behavior)
                {
                    behavior = 0;
                }

                Shell.Current.FlyoutBehavior = (FlyoutBehavior)behavior;
            }
예제 #10
0
            void ToggleFlyoutBehavior(object obj, Button btn)
            {
                var behavior = (int)(Shell.Current.FlyoutBehavior);

                behavior++;

                if (Enum.GetValues(typeof(FlyoutBehavior)).Length <= behavior)
                {
                    behavior = 0;
                }

                Shell.Current.FlyoutBehavior = (FlyoutBehavior)behavior;
                btn.Text = $"Flyout Behavior: {(FlyoutBehavior)behavior}";
            }
예제 #11
0
        public async Task ShellToolbarUpdatesFromNewBackButtonBehavior()
        {
            var       page      = new ContentPage();
            TestShell testShell = new TestShell(new ContentPage());
            await testShell.Navigation.PushAsync(page);

            Assert.IsTrue(testShell.Toolbar.BackButtonVisible);
            var backButtonBehavior = new BackButtonBehavior()
            {
                IsVisible = false,
            };

            Shell.SetBackButtonBehavior(page, backButtonBehavior);
            Assert.IsFalse(testShell.Toolbar.BackButtonVisible);
        }
		async void SetBackButtonBehavior(BackButtonBehavior value)
		{
			if (BackButtonBehavior == value)
				return;

			if (BackButtonBehavior != null)
				BackButtonBehavior.PropertyChanged -= OnBackButtonBehaviorPropertyChanged;

			BackButtonBehavior = value;

			if (BackButtonBehavior != null)
				BackButtonBehavior.PropertyChanged += OnBackButtonBehaviorPropertyChanged;

			await UpdateToolbarItems().ConfigureAwait(false);
		}
예제 #13
0
        public async Task BackButtonDisabledWhenCommandDisabled()
        {
            var       page      = new ContentPage();
            TestShell testShell = new TestShell(new ContentPage());
            await testShell.Navigation.PushAsync(page);

            var backButtonBehavior = new BackButtonBehavior();

            Shell.SetBackButtonBehavior(page, backButtonBehavior);
            Assert.IsTrue(testShell.Toolbar.BackButtonEnabled);

            bool canExecute = false;

            backButtonBehavior.Command = new Command(() => { }, () => canExecute);
            Assert.IsFalse(testShell.Toolbar.BackButtonEnabled);
            canExecute = true;
            (backButtonBehavior.Command as Command).ChangeCanExecute();
            Assert.IsTrue(testShell.Toolbar.BackButtonEnabled);
        }
예제 #14
0
        public Task NavigateTo <T>(object parameter = null, bool modal = false) where T : BasePageModel
        {
            var pageModel = Activator.CreateInstance <T>();

            var pageType = GetPageTypeName(pageModel.GetType());

            var page = (Page)Activator.CreateInstance(pageType);

            pageModel.Parameter   = parameter;
            pageModel.CurrentPage = page;
            pageModel.Initialize();



            page.BindingContext = pageModel;

            if (pageModel.HandleBackCommandImpl)
            {
                var backButtonBehavior = new BackButtonBehavior();

                backButtonBehavior.SetBinding(BackButtonBehavior.CommandProperty, new Binding
                {
                    Path   = nameof(BasePageModel.BackCommand),
                    Source = page.BindingContext,
                    Mode   = BindingMode.OneWay
                });

                Shell.SetBackButtonBehavior(page, backButtonBehavior);
            }


            if (modal)
            {
                Shell.Current.Navigation.PushModalAsync(page, animated: false);
            }
            else
            {
                Shell.Current.Navigation.PushAsync(page, animated: false);
            }
            return(Task.CompletedTask);
        }
예제 #15
0
        void SetBackButtonBehavior(BackButtonBehavior value)
        {
            if (BackButtonBehavior == value)
            {
                return;
            }

            if (BackButtonBehavior != null)
            {
                BackButtonBehavior.PropertyChanged -= OnBackButtonBehaviorPropertyChanged;
            }

            BackButtonBehavior = value;

            if (BackButtonBehavior != null)
            {
                BackButtonBehavior.PropertyChanged += OnBackButtonBehaviorPropertyChanged;
            }

            UpdateToolbarItems();
        }