Ejemplo n.º 1
0
        public void BindingContextFlyoutItems()
        {
            var flyoutItemVM = new TestShellViewModel()
            {
                Text = "Dog"
            };

            Shell shell = new Shell();

            shell.BindingContext = flyoutItemVM;

            var item1 = CreateShellItem <FlyoutItem>();

            item1.SetBinding(FlyoutItem.TitleProperty, "Text", mode: BindingMode.TwoWay);
            shell.Items.Add(item1);

            MenuItem menuItem = new MenuItem();

            menuItem.SetBinding(MenuItem.TextProperty, "Text", mode: BindingMode.TwoWay);
            shell.Items.Add(menuItem);

            var flyoutItemLabel = GetFlyoutItemDataTemplateElement <Label>(shell, shell.Items[0]);
            var menuItemLabel   = GetFlyoutItemDataTemplateElement <Label>(shell, shell.Items[1]);

            Assert.AreEqual("Dog", flyoutItemLabel.Text);
            Assert.AreEqual("Dog", menuItemLabel.Text);

            flyoutItemVM.Text = "Cat";

            Assert.AreEqual("Cat", flyoutItemLabel.Text);
            Assert.AreEqual("Cat", menuItemLabel.Text);
        }
Ejemplo n.º 2
0
        public void BindingContextSetsCorrectlyWhenUsingAsMultipleItemAndImplicitlyGeneratedShellSections()
        {
            Shell      shell = new Shell();
            FlyoutItem item  = new FlyoutItem()
            {
                FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems
            };
            ShellContent shellContent1 = new ShellContent();

            ShellContent shellContent2 = new ShellContent();

            item.Items.Add(shellContent1);
            item.Items.Add(shellContent2);
            shell.Items.Add(item);

            var vm = new TestShellViewModel();

            vm.SubViewModel = new TestShellViewModel()
            {
                Text = "Item1"
            };
            vm.SubViewModel2 = new TestShellViewModel()
            {
                Text = "Item2"
            };
            shell.BindingContext = vm;

            shellContent1.SetBinding(BindableObject.BindingContextProperty, "SubViewModel");
            shellContent2.SetBinding(BindableObject.BindingContextProperty, "SubViewModel2");

            shell.ItemTemplate = new DataTemplate(() =>
            {
                Label label = new Label();

                label.SetBinding(Label.TextProperty, "BindingContext.Text");
                return(label);
            });

            var flyoutItems = (shell as IShellController).GenerateFlyoutGrouping();


            var label1 = GetFlyoutItemDataTemplateElement <Label>(shell, flyoutItems[0][0]);
            var label2 = GetFlyoutItemDataTemplateElement <Label>(shell, flyoutItems[0][1]);

            Assert.AreEqual(label1.BindingContext, shellContent1);
            Assert.AreEqual(label2.BindingContext, shellContent2);

            Assert.AreEqual("Item1", label1.Text);
            Assert.AreEqual("Item2", label2.Text);
        }