Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="MaterialRadioButtonGroup"/>.
        /// </summary>
        public MaterialRadioButtonGroup()
        {
            BindableLayout.SetItemTemplate(this.selectionList, new DataTemplate(() =>
            {
                var radio = new MaterialRadioButton()
                {
                    FontFamily        = this.FontFamily,
                    FontSize          = this.FontSize,
                    HorizontalSpacing = this.HorizontalSpacing,
                    SelectedColor     = this.SelectedColor,
                    TextColor         = this.TextColor,
                    UnselectedColor   = this.UnselectedColor,
                    VerticalSpacing   = this.VerticalSpacing
                };

                radio.SetBinding(BaseMaterialSelectionControl.FontFamilyProperty, nameof(FontFamily));
                radio.SetBinding(BaseMaterialSelectionControl.FontSizeProperty, nameof(FontSize));
                radio.SetBinding(BaseMaterialSelectionControl.HorizontalSpacingProperty, nameof(HorizontalSpacing));
                radio.SetBinding(BaseMaterialSelectionControl.IsSelectedProperty, nameof(radio.IsSelected));
                radio.SetBinding(BaseMaterialSelectionControl.SelectedChangeCommandProperty, nameof(radio.SelectedChangeCommand));
                radio.SetBinding(BaseMaterialSelectionControl.TextProperty, nameof(radio.Text));
                radio.SetBinding(BaseMaterialSelectionControl.SelectedColorProperty, nameof(this.SelectedColor));
                radio.SetBinding(BaseMaterialSelectionControl.TextColorProperty, nameof(this.TextColor));
                radio.SetBinding(BaseMaterialSelectionControl.UnselectedColorProperty, nameof(this.UnselectedColor));
                radio.SetBinding(BaseMaterialSelectionControl.VerticalSpacingProperty, nameof(this.VerticalSpacing));

                return(radio);
            }));
        }
Beispiel #2
0
        public PersonBindableLayout()
        {
            /* NOTE: All these versions of DataTemplate work.  I'm just leaving these here for example reasons. */

            var personList = (List <Person>)GetValue(BindableLayout.ItemsSourceProperty);

            BindableLayout.SetItemsSource(this, personList);
            BindableLayout.SetItemTemplate(this, new DataTemplate(typeof(PersonView)));

            //BindableLayout.SetItemTemplate(this, new DataTemplate(() => new PersonView()));
            //BindableLayout.SetItemTemplate(this, new DataTemplate(() => { return new PersonView(); }));
        }
Beispiel #3
0
        public void ThrowsExceptionOnUsingDataTemplateSelectorForItemTemplate()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
            };

            var itemsSource = new ObservableCollection <int>(Enumerable.Range(0, 10));

            BindableLayout.SetItemsSource(layout, itemsSource);

            Assert.Throws(typeof(NotSupportedException), () => BindableLayout.SetItemTemplate(layout, new DataTemplateSelectorFrame()));
        }
Beispiel #4
0
        public void ValidateBindableProperties()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
            };

            // EmptyView
            object emptyView = new object();

            BindableLayout.SetEmptyView(layout, emptyView);

            Assert.AreEqual(emptyView, BindableLayout.GetEmptyView(layout));
            Assert.AreEqual(emptyView, layout.GetValue(BindableLayout.EmptyViewProperty));

            // EmptyViewTemplateProperty
            DataTemplate emptyViewTemplate = new DataTemplate(typeof(Label));

            BindableLayout.SetEmptyViewTemplate(layout, emptyViewTemplate);

            Assert.AreEqual(emptyViewTemplate, BindableLayout.GetEmptyViewTemplate(layout));
            Assert.AreEqual(emptyViewTemplate, layout.GetValue(BindableLayout.EmptyViewTemplateProperty));


            // ItemsSourceProperty
            IEnumerable itemsSource = new object[0];

            BindableLayout.SetItemsSource(layout, itemsSource);

            Assert.AreEqual(itemsSource, BindableLayout.GetItemsSource(layout));
            Assert.AreEqual(itemsSource, layout.GetValue(BindableLayout.ItemsSourceProperty));

            // ItemTemplateProperty
            DataTemplate itemTemplate = new DataTemplate(typeof(Label));

            BindableLayout.SetItemTemplate(layout, itemTemplate);

            Assert.AreEqual(itemTemplate, BindableLayout.GetItemTemplate(layout));
            Assert.AreEqual(itemTemplate, layout.GetValue(BindableLayout.ItemTemplateProperty));


            // ItemTemplateSelectorProperty
            var itemTemplateSelector = new DataTemplateSelectorFrame();

            BindableLayout.SetItemTemplateSelector(layout, itemTemplateSelector);

            Assert.AreEqual(itemTemplateSelector, BindableLayout.GetItemTemplateSelector(layout));
            Assert.AreEqual(itemTemplateSelector, layout.GetValue(BindableLayout.ItemTemplateSelectorProperty));
        }
Beispiel #5
0
        public void ItemTemplateTakesPrecendenceOverItemTemplateSelector()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
            };

            var itemsSource = new ObservableCollection <int>(Enumerable.Range(0, 10));

            BindableLayout.SetItemsSource(layout, itemsSource);
            BindableLayout.SetItemTemplate(layout, new DataTemplateBoxView());
            BindableLayout.SetItemTemplateSelector(layout, new DataTemplateSelectorFrame());

            Assert.IsTrue(IsLayoutWithItemsSource(itemsSource, layout));
            Assert.AreEqual(itemsSource.Count, layout.Children.Cast <BoxView>().Count());
        }
Beispiel #6
0
        public ColorListPageCS()
        {
            DataTemplate dataTemplate = new DataTemplate(() =>
            {
                BoxView boxView = new BoxView
                {
                    HeightRequest   = 32,
                    WidthRequest    = 32,
                    VerticalOptions = LayoutOptions.Center
                };
                boxView.SetBinding(BoxView.ColorProperty, "Color");

                Label label = new Label
                {
                    FontSize        = 24,
                    VerticalOptions = LayoutOptions.Center
                };
                label.SetBinding(Label.TextProperty, "FriendlyName");

                StackLayout horizontalStackLayout = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        boxView,
                        label
                    }
                };

                return(horizontalStackLayout);
            });

            StackLayout stackLayout = new StackLayout();

            BindableLayout.SetItemsSource(stackLayout, NamedColor.All);
            BindableLayout.SetItemTemplate(stackLayout, dataTemplate);

            ScrollView scrollView = new ScrollView
            {
                Margin  = new Thickness(20),
                Content = stackLayout
            };

            Title   = "ScrollView demo";
            Content = scrollView;
        }
        /// <summary>
        /// Adapts a <see cref="Layout{View}"/> to an <see cref="IRegion"/>.
        /// </summary>
        /// <param name="region">The new region being used.</param>
        /// <param name="regionTarget">The object to adapt.</param>
        protected override void Adapt(IRegion region, Layout <View> regionTarget)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            if (regionTarget == null)
            {
                throw new ArgumentNullException(nameof(regionTarget));
            }

            bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);

            if (itemsSourceIsSet)
            {
                throw new InvalidOperationException(Resources.LayoutViewHasChildrenException);
            }

            BindableLayout.SetItemsSource(regionTarget, region.Views);
            BindableLayout.SetItemTemplate(regionTarget, new RegionItemsSourceTemplate());
        }
Beispiel #8
0
        public AtomFormItemsControl(AtomForm form)
        {
            this.Form          = form;
            layout             = new StackLayout();
            this.Content       = layout;
            layout.Orientation = StackOrientation.Vertical;

            var dt = new DataTemplate(() =>
            {
                // Grid grid = new Grid();
                var afg = Form.FieldStyle.CreateContent() as AtomFieldGrid;
                if (afg == null)
                {
                    throw new InvalidOperationException("FieldStyle must contain root element of type AtomFieldGrid");
                }
                afg.Form = this.Form;
                return(afg);
            });

            BindableLayout.SetItemTemplate(layout, dt);

            layout.Spacing = 5;
        }
 public static TLayout ItemTemplate <TLayout>(this TLayout layout, Func <object> loadTemplate) where TLayout : Layout <View>
 {
     BindableLayout.SetItemTemplate(layout, new DataTemplate(loadTemplate)); return(layout);
 }
 public static TLayout ItemTemplate <TLayout>(this TLayout layout, DataTemplate template) where TLayout : Layout <View>
 {
     BindableLayout.SetItemTemplate(layout, template); return(layout);
 }
Beispiel #11
0
        public async void SwitchToTemplate(State state, string customState, bool animate)
        {
            Layout <View> layout;

            if (!_layoutWeakReference.TryGetTarget(out layout))
            {
                return;
            }

            // Put the original content somewhere where we can restore it.
            if (_previousState == State.None)
            {
                _originalContent = new List <View>();

                foreach (var item in layout.Children)
                {
                    _originalContent.Add(item);
                }
            }

            if (HasTemplateForState(state, customState))
            {
                _previousState = state;

                await ChildrenFadeTo(layout, animate, true);

                layout.Children.Clear();

                var repeatCount = GetRepeatCount(state, customState);

                if (repeatCount == 1)
                {
                    var s = new StackLayout {
                        Opacity = animate ? 0 : 1
                    };

                    if (layout is Grid grid)
                    {
                        if (grid.RowDefinitions.Any())
                        {
                            Grid.SetRowSpan(s, grid.RowDefinitions.Count);
                        }

                        if (grid.ColumnDefinitions.Any())
                        {
                            Grid.SetColumnSpan(s, grid.ColumnDefinitions.Count);
                        }

                        layout.Children.Add(s);

                        _layoutIsGrid = true;
                    }

                    var view = CreateItemView(state, customState);

                    if (view != null)
                    {
                        if (_layoutIsGrid)
                        {
                            s.Children.Add(view);
                        }
                        else
                        {
                            layout.Children.Add(view);
                        }
                    }
                }
                else
                {
                    var template = GetRepeatTemplate(state, customState);
                    var items    = new List <int>();

                    for (int i = 0; i < repeatCount; i++)
                    {
                        items.Add(i);
                    }

                    var s = new StackLayout {
                        Opacity = animate ? 0 : 1
                    };

                    if (layout is Grid grid)
                    {
                        if (grid.RowDefinitions.Any())
                        {
                            Grid.SetRowSpan(s, grid.RowDefinitions.Count);
                        }

                        if (grid.ColumnDefinitions.Any())
                        {
                            Grid.SetColumnSpan(s, grid.ColumnDefinitions.Count);
                        }
                    }

                    BindableLayout.SetItemTemplate(s, template);
                    BindableLayout.SetItemsSource(s, items);

                    layout.Children.Add(s);
                }
                await ChildrenFadeTo(layout, animate, false);
            }
        }
        public RefreshViewDemoPage()
        {
            RefreshViewDemoPageViewModel viewModel = new RefreshViewDemoPageViewModel();

            // Define DataTemplate.
            DataTemplate colorItemTemplate = new DataTemplate(() =>
            {
                Grid grid = new Grid
                {
                    Margin        = new Thickness(5),
                    HeightRequest = 120,
                    WidthRequest  = 105
                };

                BoxView boxView = new BoxView();
                boxView.SetBinding(BoxView.ColorProperty, "Color");

                Label label = new Label
                {
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center
                };
                label.SetBinding(Label.TextProperty, "Name");

                grid.Children.Add(boxView);
                grid.Children.Add(label);
                return(grid);
            });

            Label header = new Label
            {
                Text              = "RefreshView",
                FontSize          = 50,
                FontAttributes    = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Center
            };

            Label pullMessage = new Label
            {
                Text = "Pull the items down to refresh the ScrollView."
            };

            Label numberOfItems = new Label();

            numberOfItems.SetBinding(Label.TextProperty, "Items.Count", stringFormat: "Number of items: {0}");

            FlexLayout flexLayout = new FlexLayout
            {
                Direction    = FlexDirection.Row,
                Wrap         = FlexWrap.Wrap,
                AlignItems   = FlexAlignItems.Center,
                AlignContent = FlexAlignContent.Center
            };

            BindableLayout.SetItemsSource(flexLayout, viewModel.Items);
            BindableLayout.SetItemTemplate(flexLayout, colorItemTemplate);

            // Set the FlexLayout as the child of the ScrollView.
            ScrollView scrollView = new ScrollView
            {
                Content = flexLayout
            };

            // Set the ScrollView as the child of the RefreshView.
            RefreshView refreshView = new RefreshView
            {
                Content      = scrollView,
                RefreshColor = Color.Teal
            };

            refreshView.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");
            refreshView.SetBinding(RefreshView.CommandProperty, "RefreshCommand");

            // Build the page.
            Title          = "RefreshView Demo";
            BindingContext = viewModel;
            Content        = new StackLayout
            {
                Margin   = new Thickness(10),
                Children =
                {
                    header,
                    pullMessage,
                    numberOfItems,
                    refreshView
                }
            };
        }
Beispiel #13
0
        public Dashboard(User user)
        {
            this._User = user;

            NavigationPage.SetTitleView(this, new FlexLayout
            {
                Direction      = FlexDirection.Row,
                AlignContent   = FlexAlignContent.Center,
                AlignItems     = FlexAlignItems.Center,
                JustifyContent = FlexJustify.SpaceBetween,
                Padding        = new Thickness(10, 0),
                Children       =
                {
                    new Label
                    {
                        Text           = "RC Camera Car",
                        TextColor      = Color.White,
                        FontAttributes = FontAttributes.Bold,
                        FontSize       = 24
                    },
                    new Button
                    {
                        Text              = "Log Out",
                        FontAttributes    = FontAttributes.Bold,
                        ImageSource       = "log_out.png",
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Center,
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        Command           = new Command(() => OnLogOut()),
                        BackgroundColor   = Color.Transparent,
                        ContentLayout     = new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Right, 20)
                    }
                }
            });

            StackLayout carList = new StackLayout();

            BindableLayout.SetItemTemplate(carList, new DataTemplate(() =>
            {
                Button carBtn = new Button {
                    BackgroundColor = Color.Transparent,
                    FontSize        = 18,
                    FontAttributes  = FontAttributes.Bold
                };
                carBtn.SetBinding(Button.TextProperty, "Name");
                carBtn.SetBinding(IsEnabledProperty, "IsOn");
                carBtn.SetBinding(Button.CommandParameterProperty, "ID");

                carBtn.Clicked += OnCarSelect;

                return(carBtn);
            }));

            RefreshView refresh = new RefreshView
            {
                Content = new ScrollView {
                    Content = carList
                }
            };

            refresh.Command = new Command(() =>
            {
                RefreshCars(carList, refresh);
            });

            RefreshCars(carList, refresh);

            this.Content = new FlexLayout
            {
                Direction      = FlexDirection.Column,
                JustifyContent = FlexJustify.SpaceBetween,
                Padding        = new Thickness(20),
                Children       =
                {
                    new StackLayout
                    {
                        Children =
                        {
                            new FlexLayout
                            {
                                Direction      = FlexDirection.Row,
                                JustifyContent = FlexJustify.SpaceBetween,
                                AlignItems     = FlexAlignItems.Center,
                                Margin         = new Thickness(0, 0, 0, 10),
                                Children       =
                                {
                                    new Label
                                    {
                                        Text           = "Your Cars",
                                        TextColor      = Color.Black,
                                        FontSize       = 24,
                                        FontAttributes = FontAttributes.Bold
                                    },
                                    new ImageButton
                                    {
                                        Source          = "refresh.png",
                                        BackgroundColor = Color.Transparent,
                                        Scale           = 0.5,
                                        Command         = new Command(() => {
                                            refresh.IsRefreshing = true;
                                            RefreshCars(carList, refresh);
                                        })
                                    },
                                    new ImageButton
                                    {
                                        Source          = "add.png",
                                        BackgroundColor = Color.Transparent,
                                        Scale           = 0.5,
                                        Command         = new Command(() => OnRegisterCar())
                                    }
                                }
                            },
                            refresh
                        }
                    },
                    new Label
                    {
                        Text                    = "Press the + button to register a new car!",
                        FontSize                = 18,
                        TextColor               = Color.DarkGray,
                        HorizontalOptions       = LayoutOptions.Center,
                        VerticalOptions         = LayoutOptions.Center,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Center,
                        Margin                  = new Thickness(0, 20)
                    }
                }
            };
        }
Beispiel #14
0
        public WindowsRefreshViewPageCS()
        {
            WindowsRefreshViewPageViewModel viewModel = new WindowsRefreshViewPageViewModel();

            // Define DataTemplate.
            DataTemplate colorItemTemplate = new DataTemplate(() =>
            {
                Grid grid = new Grid
                {
                    Margin        = new Thickness(5),
                    HeightRequest = 120,
                    WidthRequest  = 105
                };

                BoxView boxView = new BoxView();
                boxView.SetBinding(BoxView.ColorProperty, "Color");

                Label label = new Label
                {
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center
                };
                label.SetBinding(Label.TextProperty, "Name");

                grid.Children.Add(boxView);
                grid.Children.Add(label);
                return(grid);
            });

            Label pullDirection = new Label
            {
                Text = "Pull Direction:",
                VerticalTextAlignment = TextAlignment.Center
            };

            EnumPicker enumPicker = new EnumPicker
            {
                EnumType      = typeof(Xamarin.Forms.PlatformConfiguration.WindowsSpecific.RefreshView.RefreshPullDirection),
                SelectedIndex = 0
            };

            Label numberOfItems = new Label
            {
                HorizontalOptions = LayoutOptions.Center
            };

            numberOfItems.SetBinding(Xamarin.Forms.Label.TextProperty, "Items.Count", stringFormat: "Number of items: {0}");

            StackLayout controlsLayout = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center,
                Children          =
                {
                    pullDirection,
                    enumPicker
                }
            };

            FlexLayout flexLayout = new FlexLayout
            {
                Direction    = FlexDirection.Row,
                Wrap         = FlexWrap.Wrap,
                AlignItems   = FlexAlignItems.Center,
                AlignContent = FlexAlignContent.Center
            };

            BindableLayout.SetItemsSource(flexLayout, viewModel.Items);
            BindableLayout.SetItemTemplate(flexLayout, colorItemTemplate);

            // Set the FlexLayout as the child of the ScrollView.
            ScrollView scrollView = new ScrollView
            {
                Content = flexLayout
            };

            // Set the ScrollView as the child of the RefreshView.
            RefreshView refreshView = new RefreshView
            {
                Content      = scrollView,
                RefreshColor = Color.Teal
            };

            refreshView.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");
            refreshView.SetBinding(RefreshView.CommandProperty, "RefreshCommand");
            refreshView.On <Windows>().SetRefreshPullDirection(RefreshPullDirection.LeftToRight);

            enumPicker.SelectedIndexChanged += (s, e) =>
            {
                refreshView.On <Windows>().SetRefreshPullDirection((RefreshPullDirection)enumPicker.SelectedItem);
            };

            // Build the page.
            Title          = "RefreshView Demo";
            BindingContext = viewModel;
            Content        = new StackLayout
            {
                Margin   = new Thickness(10),
                Children =
                {
                    controlsLayout,
                    numberOfItems,
                    refreshView
                }
            };
        }
 public static T BindItemTemplate <T>(this T layout, DataTemplate template) where T : Layout
 {
     BindableLayout.SetItemTemplate(layout, template);
     return(layout);
 }
        public DiscountItemTemplate()
        {
            var gridDiscountItem = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = GridLength.Star
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    }
                }
            };

            ImgCompanyLogo = new CachedImage
            {
                WidthRequest         = 64,
                HeightRequest        = 64,
                Aspect               = Aspect.AspectFit,
                DownsampleToViewSize = true,
                ErrorPlaceholder     = "img_empty_small.png"
            };

            gridDiscountItem.Children.Add(ImgCompanyLogo, 0, 1, 0, 3);

            var txtTitle = new Label
            {
                VerticalOptions = LayoutOptions.End,
                Style           = LabelStyles.ListTitleStyle.FromResources <Style>()
            };

            txtTitle.SetBinding(Label.TextProperty, "Name");

            gridDiscountItem.Children.Add(txtTitle, 1, 0);

            #region Percent label

            var spanDiscountPercent = new Span();
            spanDiscountPercent.SetBinding(Span.TextProperty, "DiscountPercent");

            var spanDiscountType = new Span();
            spanDiscountType.SetBinding(Span.TextProperty, "DiscountType");

            var txtPercent = new Label
            {
                Style           = LabelStyles.ListPercentStyle.FromResources <Style>(),
                VerticalOptions = LayoutOptions.End,
                FormattedText   = new FormattedString
                {
                    Spans =
                    {
                        spanDiscountPercent,
                        spanDiscountType
                    }
                }
            };

            gridDiscountItem.Children.Add(txtPercent, 2, 0);

            #endregion

            #region Category layout

            var categoriesLayout = new StackLayout
            {
                Spacing     = 5,
                Orientation = StackOrientation.Horizontal
            };

            var categoryItemTemplate = new DataTemplate(typeof(CategoryItemTemplate));
            BindableLayout.SetItemTemplate(categoriesLayout, categoryItemTemplate);

            categoriesLayout.SetBinding(BindableLayout.ItemsSourceProperty, "CategoryList");

            gridDiscountItem.Children.Add(categoriesLayout, 1, 3, 1, 2);

            #endregion

            #region Description

            var txtDescription = new Label
            {
                Style    = LabelStyles.DescriptionStyle.FromResources <Style>(),
                MaxLines = 3
            };
            txtDescription.SetBinding(Label.TextProperty, "Description");

            gridDiscountItem.Children.Add(txtDescription, 1, 3, 2, 3);

            #endregion

            var boxBorder = new Frame
            {
                Margin          = new Thickness(8, 4),
                Padding         = 8,
                CornerRadius    = 1,
                BackgroundColor = MainStyles.ListBackgroundColor.FromResources <Color>(),
                BorderColor     = MainStyles.ListBorderColor.FromResources <Color>(),
                HasShadow       = false,
                Content         = gridDiscountItem
            };

            View = boxBorder;
        }