コード例 #1
0
            public DiscountTemplate(ListViewAnimation parentListView, int rowHeight)
            {
                SelectColor = (Color)App.Current.Resources[MainStyles.ListSelectColor];

                Grid gridDiscountItem = new Grid
                {
                    Padding         = new Thickness(10),
                    BackgroundColor = (Color)App.Current.Resources[MainStyles.ListBackgroundColor],
                    RowDefinitions  =
                    {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(2, GridUnitType.Star)
                        }
                    },
                    ColumnDefinitions =
                    {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                        new ColumnDefinition {
                            Width = new GridLength(4, GridUnitType.Star)
                        }
                    }
                };

                var fileNameConverter = new FileNameToImageConverter();

                // Company logo
                var imgCompanyLogo = new ImageExtended
                {
                    WidthRequest  = Device.OnPlatform(64, 64, 64),
                    HeightRequest = Device.OnPlatform(64, 64, 64),
                    Aspect        = Aspect.AspectFit,
                };

                imgCompanyLogo.SetBinding(Image.SourceProperty, new Binding("LogoFileName", BindingMode.Default, fileNameConverter));


                var stackCompanyLogo = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        = { imgCompanyLogo }
                };

                gridDiscountItem.Children.Add(stackCompanyLogo, 0, 1, 0, 2);

                // Header
                Grid headerLayout = new Grid
                {
                    Padding        = new Thickness(2, 0, 0, 0),
                    RowDefinitions =
                    {
                        new RowDefinition {
                            Height = GridLength.Auto
                        }
                    },
                    ColumnDefinitions =
                    {
                        new ColumnDefinition {
                            Width = new GridLength(3, GridUnitType.Star)
                        },
                        new ColumnDefinition {
                            Width = GridLength.Auto
                        }                                               //new GridLength(1, GridUnitType.Star)},
                    }
                };

                // Title
                var txtTitle = new Label
                {
                    VerticalOptions = LayoutOptions.End,
                    Style           = (Style)App.Current.Resources[LabelStyles.ListTitleStyle]
                };

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

                headerLayout.Children.Add(txtTitle, 0, 0);

                #region Percent label
                var txtPercent = new Label
                {
                    Style           = (Style)App.Current.Resources[LabelStyles.ListPercentStyle],
                    VerticalOptions = LayoutOptions.End
                };
                txtPercent.SetBinding(Label.TextProperty, "DiscountPercent");

                var percentLayout = new StackLayout
                {
                    Spacing     = 0,
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        txtPercent,
                        new Label
                        {
                            Style           = (Style)App.Current.Resources[LabelStyles.ListPercentSymbolStyle],
                            VerticalOptions = LayoutOptions.End
                        }
                    }
                };
                #endregion

                #region Category layout
                var txtCategory = new Label
                {
                    Style             = (Style)App.Current.Resources[LabelStyles.CategoryStyle],
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };
                txtCategory.SetBinding(Label.TextProperty, "FirstCategoryName");
                txtCategory.SetBinding(BackgroundColorProperty, "FirstCategoryColor");

                var categoryLayout = new StackLayout
                {
                    Padding           = Device.OnPlatform(new Thickness(4), new Thickness(4), new Thickness(6)),
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                    Children          =
                    {
                        txtCategory
                    }
                };
                categoryLayout.SetBinding(BackgroundColorProperty, "FirstCategoryColor");

                var txtCategoryMore = new Label
                {
                    Text              = "...",
                    Style             = (Style)App.Current.Resources[LabelStyles.CategoryStyle],
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };
                txtCategory.SetBinding(BackgroundColorProperty, "FirstCategoryColor");

                var stackCategoryMore = new StackLayout
                {
                    Padding           = Device.OnPlatform(new Thickness(4), new Thickness(4), new Thickness(6)),
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                    Children          =
                    {
                        txtCategoryMore
                    }
                };
                stackCategoryMore.SetBinding(BackgroundColorProperty, "FirstCategoryColor");
                stackCategoryMore.SetBinding(IsVisibleProperty, "IsCategoryMore");
                #endregion

                var infoDiscountLayout = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,

                    Children =
                    {
                        percentLayout,
                        categoryLayout,
                        stackCategoryMore
                    }
                };

                headerLayout.Children.Add(infoDiscountLayout, 1, 0);
                gridDiscountItem.Children.Add(headerLayout, 1, 2, 0, 1);

                #region Description
                var txtDescription = new LabelExtended
                {
                    IsWrapped = true,
                    Style     = (Style)App.Current.Resources[LabelStyles.DescriptionStyle],
                };
                txtDescription.GestureRecognizers.Clear();
                txtDescription.SetBinding(LabelExtended.TextProperty, new Binding("Description", BindingMode.Default, new TextHeightLimitation()));

                var layoutDescription = new RelativeLayout();
                layoutDescription.Children.Add(txtDescription,
                                               Constraint.Constant(2),
                                               Constraint.Constant(0),
                                               Constraint.RelativeToParent(parent => { return(parent.Width - 2); }),
                                               Constraint.RelativeToParent(parent => { return(parent.Height); }));

                gridDiscountItem.Children.Add(layoutDescription, 1, 2, 1, 2);
                #endregion

                var boxBorder = new BorderBox
                {
                    Padding       = new Thickness(8, 4),
                    HeightRequest = rowHeight - 16,
                };
                boxBorder.BorderColor = (Color)App.Current.Resources[MainStyles.ListBorderColor];
                boxBorder.BorderWidth = 1;
                boxBorder.Content     = gridDiscountItem;

                var layout = new AbsoluteLayout
                {
                    Padding = new Thickness(8, 4),
                };
                parentListView.AnimationListAdd(layout);

                AbsoluteLayout.SetLayoutFlags(boxBorder, AbsoluteLayoutFlags.All);
                AbsoluteLayout.SetLayoutBounds(boxBorder, new Rectangle(0f, 0f, 1f, 1f));
                layout.Children.Add(boxBorder);

                View = layout;
            }
コード例 #2
0
        public DiscountDetailPage(DiscountDetailData discountDetailData)
            : base(typeof(DiscountDetailViewModel), typeof(DiscountDetailContentUI))
        {
            BackgroundColor         = MainStyles.StatusBarColor.FromResources <Color>();
            Content.BackgroundColor = MainStyles.MainLightBackgroundColor.FromResources <Color>();

            viewModel.SetDiscount(discountDetailData);

            var mainLayout = new AbsoluteLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack)
            {
                BarColor   = Color.Transparent,
                BoxPadding =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>()
                },
                BtnBack =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(),
                    Source          = contentUI.IconBack
                }
            };

            #region Photo

            var imageLayout = new RelativeLayout
            {
                HeightRequest = Device.Idiom == TargetIdiom.Phone ? 200 : 400
            };

            var fileNameConverter = new FileNameToImageConverter();
            var imgPhoto          = new Image
            {
                Aspect = Aspect.AspectFill
            };
            imgPhoto.SetBinding(Image.SourceProperty,
                                new Binding("ImageFileName", BindingMode.Default, fileNameConverter, true));

            imageLayout.Children.Add(imgPhoto,
                                     Constraint.Constant(0),
                                     Constraint.Constant(0),
                                     Constraint.RelativeToParent(parent => parent.Width),
                                     Constraint.RelativeToParent(parent => parent.Height));

            #endregion

            #region Label percent

            const int sizeImgLabel = 60;

            var imgLabel = new Image
            {
                HeightRequest = sizeImgLabel,
                WidthRequest  = sizeImgLabel,
                Source        = contentUI.ImgPercentLabel
            };

            var labelLayout = new AbsoluteLayout();
            AbsoluteLayout.SetLayoutFlags(imgLabel, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(imgLabel, new Rectangle(0f, 0f, 1f, 1f));
            labelLayout.Children.Add(imgLabel);

            imageLayout.Children.Add(labelLayout,
                                     Constraint.RelativeToParent(parent => parent.Width - sizeImgLabel - 5),
                                     Constraint.RelativeToView(imgPhoto,
                                                               (parent, sibling) => sibling.Y + sibling.Height - sizeImgLabel - 5));

            var spanDiscountPercent = new Span
            {
                Style = LabelStyles.LabelPercentStyle.FromResources <Style>()
            };
            spanDiscountPercent.SetBinding(Span.TextProperty, "DiscountPercent", BindingMode.OneWay);

            var spanDiscountType = new Span
            {
                Style = LabelStyles.LabelPercentSymbolStyle.FromResources <Style>()
            };
            spanDiscountType.SetBinding(Span.TextProperty, "DiscountType", BindingMode.OneWay);

            var txtPercent = new Label
            {
                Rotation      = -15,
                TranslationY  = -1,
                FormattedText = new FormattedString
                {
                    Spans =
                    {
                        spanDiscountPercent,
                        spanDiscountType
                    }
                }
            };

            AbsoluteLayout.SetLayoutFlags(txtPercent, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(txtPercent,
                                           new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            labelLayout.Children.Add(txtPercent);

            #endregion

            #region WebAddress & Category list

            var flexCategories = new FlexLayout
            {
                Direction      = FlexDirection.Row,
                Wrap           = FlexWrap.Wrap,
                JustifyContent = FlexJustify.Start,
                AlignItems     = FlexAlignItems.Center,
                AlignContent   = FlexAlignContent.Start,
                Margin         = new Thickness(20, 15, 15, 0)
            };

            foreach (var webAddress in viewModel.WebAddresses)
            {
                var imgWebAddress = new Image
                {
                    Source = webAddress.Type.GetWebAddressIcon()
                };

                var viewGesturesWebAddress = new ViewGestures
                {
                    Content         = imgWebAddress,
                    AnimationEffect = ViewGestures.AnimationType.atScaling,
                    AnimationScale  = -5,
                    Tag             = webAddress.Url,
                    Margin          = new Thickness(0, 0, 5, 5)
                };
                viewGesturesWebAddress.Tap += viewModel.TxtUrlAddress_Click;

                flexCategories.Children.Add(viewGesturesWebAddress);
            }

            var flexSeparator = new ContentView();
            FlexLayout.SetGrow(flexSeparator, 1);
            flexCategories.Children.Add(flexSeparator);

            foreach (var category in viewModel.Categories)
            {
                var categoryLayout = new CategoryItemTemplate
                {
                    Margin         = new Thickness(0, 0, 5, 5),
                    BindingContext = category
                };

                flexCategories.Children.Add(categoryLayout);
            }

            #endregion

            #region Name company

            var txtPartnerName = new Label
            {
                Style = LabelStyles.DetailTitleStyle.FromResources <Style>()
            };
            txtPartnerName.SetBinding(Label.TextProperty, "NameCompany");

            #endregion

            #region Description

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

            #endregion

            var stackDetails = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Padding     = new Thickness(20, 0),
                Children    =
                {
                    txtPartnerName,
                    txtDescription
                }
            };

            var discountLayout = new StackLayout
            {
                Spacing     = 0,
                Orientation = StackOrientation.Vertical,
                Children    =
                {
                    imageLayout,
                    flexCategories,
                    stackDetails
                }
            };

            foreach (var brachItem in viewModel.BranchItems)
            {
                var view = new BranchInfoViewTemplate(contentUI, viewModel).View;
                view.BindingContext = brachItem;

                discountLayout.Children.Add(view);
            }

            var scrollDiscount = new ScrollView
            {
                Content = discountLayout
            };

            AbsoluteLayout.SetLayoutFlags(scrollDiscount, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(scrollDiscount, new Rectangle(0f, 0f, 1f, 1f));
            mainLayout.Children.Add(scrollDiscount);

            AbsoluteLayout.SetLayoutFlags(appBar,
                                          AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
            AbsoluteLayout.SetLayoutBounds(appBar, new Rectangle(0f, 0f, 1f, AbsoluteLayout.AutoSize));
            mainLayout.Children.Add(appBar);

            var safeAreaHelper = new SafeAreaHelper();
            safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top);
            safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left);
            safeAreaHelper.UseSafeArea(scrollDiscount, SafeAreaHelper.CustomSafeAreaFlags.Horizontal);

            ContentLayout.Children.Add(mainLayout);
        }
コード例 #3
0
        public DiscountDetailPage(string discountID)
            : base(typeof(DiscountDetailViewModel), typeof(DiscountDetailContentUI))
        {
            viewModel.SetDiscount(discountID);
            var fileNameConverter = new FileNameToImageConverter();

            BackgroundColor = (Color)App.Current.Resources[MainStyles.MainLightBackgroundColor];

            var mainLayout = new AbsoluteLayout();

            var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack)
            {
                BarColor = Color.Transparent,
            };

            appBar.BoxPadding.BackgroundColor = (Color)App.Current.Resources[MainStyles.StatusBarColor];
            appBar.BoxPadding.Opacity         = 0.9;

            appBar.BtnBack.BackgroundColor = (Color)App.Current.Resources[MainStyles.StatusBarColor];
            appBar.BtnBack.Opacity         = 0.9;
            appBar.BtnBack.Source          = contentUI.IconBack;

            discountLayout = new StackLayout
            {
                Spacing = Device.OnPlatform(0, 0, 4),
            };

            #region Photo
            var imageLayout = new RelativeLayout
            {
                HeightRequest = Device.OnPlatform(200, 200, 240)
            };

            var imgPhoto = new Image
            {
                Aspect = Aspect.AspectFill,
            };
            imgPhoto.SetBinding(Image.SourceProperty, new Binding("ImageFileName", BindingMode.Default, fileNameConverter));

            //imgPhoto.SetBinding(Image.SourceProperty, new Binding("ImgPhoto", BindingMode.Default, new FileStreamToImageSource(), FileStreamToImageSource.SizeImage.siBig));

            imageLayout.Children.Add(imgPhoto,
                                     Constraint.Constant(0),
                                     Constraint.Constant(0),
                                     Constraint.RelativeToParent(parent => { return(parent.Width); }),
                                     Constraint.RelativeToParent(parent => { return(parent.Height); })
                                     );
            #endregion

            #region Label percent
            int sizeImgLabel = Device.OnPlatform(60, 60, 80);

            var imgLabel = new Image
            {
                HeightRequest = sizeImgLabel,
                WidthRequest  = sizeImgLabel,
                Source        = contentUI.ImgPercentLabel
            };

            var labelLayout = new AbsoluteLayout();
            AbsoluteLayout.SetLayoutFlags(imgLabel, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(imgLabel, new Rectangle(0f, 0f, 1f, 1f));
            labelLayout.Children.Add(imgLabel);

            imageLayout.Children.Add(labelLayout,
                                     Constraint.RelativeToParent(parent =>
            {
                return(parent.Width - sizeImgLabel - 5);
            }),
                                     Constraint.RelativeToView(imgPhoto, (parent, sibling) =>
            {
                return(sibling.Y + sibling.Height - sizeImgLabel - 5);
            }));

            // Percent
            var txtPercent = new Label
            {
                Style = (Style)App.Current.Resources[LabelStyles.LabelPercentStyle]
            };
            txtPercent.SetBinding(Label.TextProperty, "DiscountPercent");

            var percentLayout = new StackLayout
            {
                Spacing     = 0,
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    txtPercent,
                    new Label
                    {
                        Style           = (Style)App.Current.Resources[LabelStyles.LabelPercentSymbolStyle],
                        VerticalOptions = LayoutOptions.End
                    }
                }
            };

            percentLayout.Rotation = -15;
            AbsoluteLayout.SetLayoutFlags(percentLayout, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(percentLayout,
                                           new Rectangle(0.6, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)
                                           );
            labelLayout.Children.Add(percentLayout);

            discountLayout.Children.Add(imageLayout);
            #endregion

            #region Header
            Grid gridHeader = new Grid
            {
                VerticalOptions = LayoutOptions.Start,
                Padding         = new Thickness(10),
                RowDefinitions  =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(4, GridUnitType.Star)
                    }
                }
            };

            #region Company logo
            var imgCompanyLogo = new Image
            {
                WidthRequest  = Device.OnPlatform(64, 64, 64),
                HeightRequest = Device.OnPlatform(64, 64, 64),
                Aspect        = Aspect.AspectFit
            };
            imgCompanyLogo.SetBinding(Image.SourceProperty, new Binding("LogoFileName", BindingMode.Default, fileNameConverter));
            //imgCompanyLogo.SetBinding(Image.SourceProperty, new Binding("ImgLogo", BindingMode.Default, new FileStreamToImageSource(), FileStreamToImageSource.SizeImage.siSmall));

            var stackCompanyLogo = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        = { imgCompanyLogo }
            };

            gridHeader.Children.Add(stackCompanyLogo, 0, 0);
            #endregion

            #region Category list
            var stackCategories = new StackLayout
            {
                Spacing           = 10,
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.End
            };

            for (var i = 0; i < viewModel.CategoriesCount; i++)
            {
                var txtCategory = new Label
                {
                    Style = (Style)App.Current.Resources[LabelStyles.CategoryStyle]
                };

                txtCategory.Text            = viewModel.CategoryIndexName(i);
                txtCategory.BackgroundColor = viewModel.CategoryIndexColor(i);

                var categoryLayout = new StackLayout
                {
                    Padding           = Device.OnPlatform(new Thickness(4), new Thickness(4), new Thickness(6)),
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.End,
                    Children          =
                    {
                        txtCategory
                    }
                };
                categoryLayout.BackgroundColor = viewModel.CategoryIndexColor(i);

                stackCategories.Children.Add(categoryLayout);
            }
            #endregion

            var titleDetailLayout = new StackLayout
            {
                Padding           = new Thickness(2, 0, 0, 0),
                Spacing           = Device.OnPlatform(0, 0, 4),
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            titleDetailLayout.Children.Add(stackCategories);

            #region Name company
            var txtPartnerName = new Label
            {
                Style             = (Style)App.Current.Resources[LabelStyles.DetailTitleStyle],
                HorizontalOptions = LayoutOptions.Start
            };
            txtPartnerName.SetBinding(Label.TextProperty, "NameCompany");
            titleDetailLayout.Children.Add(txtPartnerName);
            #endregion

            #region Url address
            var txtUrlAddress = new LabelExtended
            {
                Style             = (Style)App.Current.Resources[LabelStyles.LinkStyle],
                TextColor         = Color.FromHex("777"),
                HorizontalOptions = LayoutOptions.Start
            };
            txtUrlAddress.SetBinding(Label.TextProperty, "UrlAddress");

            var viewGesturesURL = new ViewGestures
            {
                Content          = txtUrlAddress,
                DeformationValue = -5,
            };
            viewGesturesURL.BackgroundColor = this.BackgroundColor;
            viewGesturesURL.Tap            += viewModel.txtUrlAddress_Click;
            titleDetailLayout.Children.Add(viewGesturesURL);
            #endregion

            gridHeader.Children.Add(titleDetailLayout, 1, 0);

            discountLayout.Children.Add(gridHeader);
            #endregion

            #region Description
            var txtDescription = new Label
            {
                Style         = (Style)App.Current.Resources[LabelStyles.DescriptionStyle],
                LineBreakMode = LineBreakMode.WordWrap
            };
            txtDescription.SetBinding(Label.TextProperty, "Description");

            var descriptionLayout = new StackLayout
            {
                Padding  = new Thickness(18, 0),
                Children =
                {
                    txtDescription
                }
            };
            discountLayout.Children.Add(descriptionLayout);
            #endregion

            discountLayout.VerticalOptions = LayoutOptions.Start;
            var scrollDiscount = new ScrollView
            {
                VerticalOptions = LayoutOptions.Start,
                Content         = discountLayout,
                HeightRequest   = Device.OnPlatform(600, 600, -1),
            };

            mainLayout.VerticalOptions = LayoutOptions.StartAndExpand;
            AbsoluteLayout.SetLayoutFlags(scrollDiscount, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(scrollDiscount, new Rectangle(0f, 0f, 1f, 1f));
            mainLayout.Children.Add(scrollDiscount);

            AbsoluteLayout.SetLayoutFlags(appBar, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(appBar,
                                           new Rectangle(0, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            mainLayout.Children.Add(appBar);

            ContentLayout.Children.Add(mainLayout);

            if (Device.OS == TargetPlatform.iOS)
            {
                InitBranchListView();
            }
        }