public void TestMarginWithSiblingRow() { Device.PlatformServices = new MockPlatformServices(getNativeSizeFunc: (visual, width, height) => new SizeRequest(new Size(0, 0))); var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 0, 10, 0) }; FlexLayout.SetGrow(view0, 1); var view1 = new View { IsPlatformEnabled = true }; FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout { IsPlatformEnabled = true, Children = { view0, view1, }, Direction = FlexDirection.Row, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 45, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(55, 0, 45, 100))); }
public void ChangingGrowTriggersLayout() //https://github.com/xamarin/Microsoft.Maui.Controls/issues/2821 { var layout = new FlexLayout { IsPlatformEnabled = true, Direction = FlexDirection.Column, }; var handler = Substitute.For <IViewHandler>(); layout.Handler = handler; layout.Layout(new Rect(0, 0, 300, 300)); for (var i = 0; i < 3; i++) { var box = new BoxView { IsPlatformEnabled = true, }; layout.Children.Add(box); FlexLayout.SetGrow(box, 1f); } // Verify the changes invalidated the layout AssertInvalidated(handler); // Fake a native invalidation layout.ForceLayout(); Assert.That(layout.Children[2].Frame, Is.EqualTo(new Rect(0, 200, 300, 100))); }
public void TestMarginWithSiblingColumn() { var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 0, 0, 10) }; FlexLayout.SetGrow(view0, 1); var view1 = new View { IsPlatformEnabled = true }; FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout { IsPlatformEnabled = true, Children = { view0, view1, }, Direction = FlexDirection.Column, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 45))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 55, 100, 45))); }
public void TestNesting() { var platform = new UnitPlatform(); var header = new View { HeightRequest = 50, IsPlatformEnabled = true, }; var footer = new View { HeightRequest = 50, IsPlatformEnabled = true, }; Func <View> createItem = () => { var v = new View { WidthRequest = 50, Margin = 5, IsPlatformEnabled = true, }; FlexLayout.SetGrow(v, 1); return(v); }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { header, new FlexLayout { Direction = FlexDirection.Row, IsPlatformEnabled = true, Children = { createItem(), createItem(), createItem(), createItem(), createItem(), } }, footer, }, Direction = FlexDirection.Column, }; var inner = layout.Children[1] as FlexLayout; FlexLayout.SetGrow(inner, 1); layout.Layout(new Rectangle(0, 0, 300, 600)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 600))); Assert.That(header.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 50))); Assert.That(inner.Bounds, Is.EqualTo(new Rectangle(0, 50, 300, 500))); Assert.That(inner.Children[0].Bounds, Is.EqualTo(new Rectangle(5, 5, 50, 490))); Assert.That(inner.Children[1].Bounds, Is.EqualTo(new Rectangle(65, 5, 50, 490))); Assert.That(inner.Children[2].Bounds, Is.EqualTo(new Rectangle(125, 5, 50, 490))); Assert.That(inner.Children[3].Bounds, Is.EqualTo(new Rectangle(185, 5, 50, 490))); Assert.That(inner.Children[4].Bounds, Is.EqualTo(new Rectangle(245, 5, 50, 490))); Assert.That(footer.Bounds, Is.EqualTo(new Rectangle(0, 550, 300, 50))); }
public void TestAlignContentStretchRowWithFlex() { var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, AlignContent = FlexAlignContent.Stretch, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, }; var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view1, 1); FlexLayout.SetShrink(view1, 1); FlexLayout.SetBasis(view1, 0); layout.Children.Add(view1); var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view2); var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view3, 1); FlexLayout.SetShrink(view3, 1); FlexLayout.SetBasis(view3, 0); layout.Children.Add(view3); var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view4); layout.Layout(new Rectangle(0, 0, 150, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 150, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(50, 0, 0, 100))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(50, 0, 50, 100))); Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(100, 0, 0, 100))); Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(100, 0, 50, 100))); }
// fixed at https://github.com/xamarin/flex/commit/0ccb9f1625abdc5400def29651373937bf6610cd public void TestSwapChildrenOrder() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, Platform = platform, IsPlatformEnabled = true, }; var label0 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label0" }; FlexLayout.SetGrow(label0, 1); layout.Children.Add(label0); var label1 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label1" }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label2" }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(new Rectangle(0, 0, 100, 50), label0.Bounds); Assert.AreEqual(new Rectangle(100, 0, 100, 50), label1.Bounds); Assert.AreEqual(new Rectangle(200, 0, 100, 50), label2.Bounds); var lastItem = layout.Children[2]; Assert.That(lastItem, Is.SameAs(label2)); layout.Children.Remove(lastItem); Assert.AreEqual(new Rectangle(0, 0, 150, 50), label0.Bounds); Assert.AreEqual(new Rectangle(150, 0, 150, 50), label1.Bounds); layout.Children.Insert(0, lastItem); Assert.AreEqual(new Rectangle(0, 0, 100, 50), label2.Bounds); Assert.AreEqual(new Rectangle(100, 0, 100, 50), label0.Bounds); Assert.AreEqual(new Rectangle(200, 0, 100, 50), label1.Bounds); }
public void TestSetBounds() { var layoutSize = new Size(320, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, AlignItems = FlexAlignItems.Start, Platform = platform, IsPlatformEnabled = true }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(label2.Bounds.Left, Math.Max(label1.Bounds.Left, label1.Bounds.Right), 1); Assert.AreEqual(label3.Bounds.Left, Math.Max(label2.Bounds.Left, label2.Bounds.Right), 1); double totalWidth = 0; foreach (var view in layout.Children) { totalWidth += view.Bounds.Width; } Assert.AreEqual(layoutSize.Width, totalWidth, 2); }
public void TestMarginsWithWrap() { var platform = new UnitPlatform(); var label0 = new Label { Platform = platform, IsPlatformEnabled = true, Margin = 6, }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true, Margin = 6, }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, }; FlexLayout.SetGrow(label0, 0); FlexLayout.SetBasis(label0, new FlexBasis(.5f, true)); FlexLayout.SetGrow(label1, 0); FlexLayout.SetBasis(label1, new FlexBasis(.5f, true)); FlexLayout.SetGrow(label2, 0); FlexLayout.SetBasis(label2, new FlexBasis(1f, true)); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, AlignItems = FlexAlignItems.Start, AlignContent = FlexAlignContent.Start, Children = { label0, label1, label2, } }; var measure = layout.Measure(300, double.PositiveInfinity); Assert.That(measure.Request, Is.EqualTo(new Size(300, 52))); layout.Layout(new Rectangle(0, 0, 300, 300)); Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(6, 6, 138, 20))); Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(156, 6, 138, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 32, 300, 20))); }
public void TestRelayoutOnChildrenRemoved() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); foreach (var view in layout.Children) { Assert.That(view.Bounds.Width, Is.EqualTo(100)); } layout.Children.Remove(label3); Assert.That(label1.Bounds.Width, Is.EqualTo(150)); Assert.That(label2.Bounds.Width, Is.EqualTo(150)); Assert.That(label3.Bounds.Width, Is.EqualTo(100)); }
public void TestFlexLayoutIsIncludeChangeWorksOnSecondPass() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, Platform = platform, IsPlatformEnabled = true, }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(150, label1.Bounds.Width); Assert.AreEqual(150, label2.Bounds.Width); Assert.AreEqual(-1, label3.Bounds.Width); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(100, label1.Bounds.Width); Assert.AreEqual(100, label2.Bounds.Width); Assert.AreEqual(100, label3.Bounds.Width); }
//https://github.com/xamarin/Xamarin.Forms/issues/2551 public void TestReverseWithGrow() { var label0 = new Label { IsPlatformEnabled = true, }; FlexLayout.SetGrow(label0, 1); var layout = new FlexLayout { IsPlatformEnabled = true, Direction = FlexDirection.ColumnReverse, Children = { label0, } }; layout.Layout(new Rectangle(0, 0, 300, 300)); Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 300))); }
public void TestMarginAndStretchColumn() { var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(10, 0, 10, 0) }; FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { IsPlatformEnabled = true, Children = { view0, }, Direction = FlexDirection.Column, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(10, 0, 80, 100))); }
public void ChangingGrowTriggersLayout() //https://github.com/xamarin/Xamarin.Forms/issues/2821 { var layout = new FlexLayout { IsPlatformEnabled = true, Direction = FlexDirection.Column, }; layout.Layout(new Rectangle(0, 0, 300, 300)); for (var i = 0; i < 3; i++) { var box = new BoxView { IsPlatformEnabled = true, }; layout.Children.Add(box); FlexLayout.SetGrow(box, 1f); } Assert.That(layout.Children[2].Bounds, Is.EqualTo(new Rectangle(0, 200, 300, 100))); }
public void TestMarginAndStretchRow() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, Margin = new Thickness(0, 10, 0, 10), }; FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, }, Direction = FlexDirection.Row, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 10, 100, 80))); }
public FlexHeightShrinkPage() { InitializeComponent(); var flexRoot = new FlexLayout { Direction = FlexDirection.Column }; var upperFlex = new FlexLayout { BackgroundColor = Color.Red }; upperFlex.Children.Add(new Label { Text = "Upper" }); FlexLayout.SetGrow(upperFlex, 1); flexRoot.Children.Add(upperFlex); var bottomFlex = new FlexLayout { BackgroundColor = Color.Yellow }; bottomFlex.Children.Add(new Label { Text = "Bottom" }); FlexLayout.SetBasis(bottomFlex, 100); flexRoot.Children.Add(bottomFlex); Content = flexRoot; }
public void Grow() { FlexLayout.SetGrow(Bindable, 0f); Bindable.Grow(1f); Assert.That(FlexLayout.GetGrow(Bindable), Is.EqualTo(1f)); }
public void TestAlignContentFlexStartWithFlex() { var platform = new UnitPlatform((visual, width, height) => new SizeRequest(new Size(0, 0))); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, WidthRequest = 100, HeightRequest = 120, Direction = FlexDirection.Column, Wrap = FlexWrap.Wrap, AlignItems = FlexAlignItems.Start, }; var view0 = new View { IsPlatformEnabled = true }; FlexLayout.SetGrow(view0, 1); FlexLayout.SetBasis(view0, 0); view0.WidthRequest = 50; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true }; FlexLayout.SetGrow(view1, 1); FlexLayout.SetBasis(view1, 0); view1.WidthRequest = 50; view1.HeightRequest = 10; layout.Children.Add(view1); var view2 = new View { IsPlatformEnabled = true }; view2.WidthRequest = 50; layout.Children.Add(view2); var view3 = new View { IsPlatformEnabled = true }; FlexLayout.SetGrow(view3, 1); FlexLayout.SetShrink(view3, 1); FlexLayout.SetBasis(view3, 0); view3.WidthRequest = 50; layout.Children.Add(view3); var view4 = new View { IsPlatformEnabled = true }; view4.WidthRequest = 50; layout.Children.Add(view4); layout.Layout(new Rectangle(0, 0, 100, 120)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 120))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 40))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 40, 50, 40))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 80, 50, 0))); Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(0, 80, 50, 40))); Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(0, 120, 50, 0))); }
public static T Grow <T>(this T view) where T : View { FlexLayout.SetGrow(view, 1); return(view); }
public void Grow() => AssertExperimental(() => { FlexLayout.SetGrow(Bindable, 0f); Bindable.Grow(1f); Assert.That(FlexLayout.GetGrow(Bindable), Is.EqualTo(1f)); });
private void SelfInit() { var tapRecognizer = new TapGestureRecognizer(); tabContainer = new FlexLayout { BackgroundColor = SelectedTextBGColor, Padding = new Thickness(0, 0, 0, TabMargin * 2) }; tabLabels = new List <Label>(); int i = 0; try{ TabSource.ForEach(t => { var label = new Label { Text = t.ToString(), TextColor = TabTextColor, WidthRequest = TabWidth, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, BackgroundColor = TabBGColor, Margin = new Thickness(TabMargin, 0), ClassId = i.ToString(), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), GestureRecognizers = { tapRecognizer } }; tabLabels.Add(label); tabContainer.Children.Add(label); i++; }); }catch { } tapRecognizer.Tapped += async(o, args) => { await detail.FadeTo(0, 100); Label selectedLabel = tabContainer.Children.Where(l => l.ClassId == selected).FirstOrDefault() as Label; selectedLabel.BackgroundColor = TabBGColor; selectedLabel.TextColor = TabTextColor; Label label = o as Label; selected = label.ClassId; label.BackgroundColor = SelectedTextBGColor; label.TextColor = SelectedTextColor; //detail.Text = DetailSrouce[int.Parse(selected)]; await detail.FadeTo(1, 100); }; detail = new Editor { BackgroundColor = Color.Azure }; FlexLayout.SetBasis(detail, new FlexBasis(0.9f, true)); FlexLayout.SetGrow(detail, 1f); var scrollView = new ScrollView { Content = tabContainer, Orientation = ScrollOrientation.Horizontal }; FlexLayout.SetBasis(scrollView, new FlexBasis(0.1f, true)); frame = new Frame { Padding = new Thickness(1), HasShadow = true, BorderColor = Color.FromHex("#101A40") }; frame.Content = new FlexLayout { Direction = FlexDirection.Column, JustifyContent = FlexJustify.Start, Children = { scrollView, detail }, }; selected = "0"; try { tabContainer.Children[0].BackgroundColor = SelectedTextBGColor; } catch { } }
public static TView Grow <TView>(this TView view, float value) where TView : View { VerifyExperimental(); FlexLayout.SetGrow(view, value); return(view); }
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); }
public static TView Grow <TView>(this TView view, float value) where TView : View { FlexLayout.SetGrow(view, value); return(view); }
public FlexLayoutDemoPage() { FlexLayout flexLayout = new FlexLayout(); foreach (DataItem item in data) { FlexLayout itemFlexLayout = new FlexLayout { Direction = FlexDirection.Column, Children = { new Label { Text = item.Header, Margin = new Thickness(0, 8), FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), TextColor = Color.Blue, }, new Label { Text = item.Description, Margin = new Thickness(0, 4), }, } }; foreach (string bullet in item.Bullets) { itemFlexLayout.Children.Add(new Label { Text = " \u2022 " + bullet, Margin = new Thickness(0, 4) }); } var x = ImageSource.FromResource(""); Image image = new Image { Source = ImageSource.FromResource("FormsGallery.Images." + item.Image), WidthRequest = item.ImageWidth, HeightRequest = 180 }; FlexLayout.SetOrder(image, -1); FlexLayout.SetAlignSelf(image, FlexAlignSelf.Center); itemFlexLayout.Children.Add(image); Label blankLabel = new Label(); FlexLayout.SetGrow(blankLabel, 1); itemFlexLayout.Children.Add(blankLabel); itemFlexLayout.Children.Add(new Button { Text = "LEARN MORE", FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)), TextColor = Color.White, BackgroundColor = Color.Green, CornerRadius = 20 }); flexLayout.Children.Add(new Frame { WidthRequest = 300, HeightRequest = 480, BackgroundColor = Color.LightYellow, BorderColor = Color.Blue, Margin = new Thickness(10), CornerRadius = 15, Content = itemFlexLayout }); } // Build the page. Title = "FlexLayout Demo"; Content = new ScrollView { Orientation = ScrollOrientation.Both, Content = flexLayout }; }
public void TestAlignContentStretchRowWithFlexNoShrink() { var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row, AlignContent = FlexAlignContent.Stretch, Wrap = FlexWrap.Wrap, WidthRequest = 150, HeightRequest = 100 }; var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view1, 1); FlexLayout.SetShrink(view1, 1); FlexLayout.SetBasis(view1, 0); layout.Children.Add(view1); var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view2); var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view3, 1); FlexLayout.SetBasis(view3, 0); layout.Children.Add(view3); var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view4); layout.Layout(new Rectangle(0, 0, 150, 100)); Assert.AreEqual(0f, layout.X); Assert.AreEqual(0f, layout.Y); Assert.AreEqual(150f, layout.Width); Assert.AreEqual(100f, layout.Height); Assert.AreEqual(0f, view0.X); Assert.AreEqual(0f, view0.Y); Assert.AreEqual(50f, view0.Width); Assert.AreEqual(100f, view0.Height); Assert.AreEqual(50f, view1.X); Assert.AreEqual(0f, view1.Y); Assert.AreEqual(0f, view1.Width); Assert.AreEqual(100f, view1.Height); Assert.AreEqual(50f, view2.X); Assert.AreEqual(0f, view2.Y); Assert.AreEqual(50f, view2.Width); Assert.AreEqual(100f, view2.Height); Assert.AreEqual(100f, view3.X); Assert.AreEqual(0f, view3.Y); Assert.AreEqual(0f, view3.Width); Assert.AreEqual(100f, view3.Height); Assert.AreEqual(100f, view4.X); Assert.AreEqual(0f, view4.Y); Assert.AreEqual(50f, view4.Width); Assert.AreEqual(100f, view4.Height); }
public View CreateViewCaptionValue(string caption = "", string centerText = null, object value = null, Action onClicked = null) { var bigCaption = caption.StartsWith("#"); var view = new FlexLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, AlignContent = FlexAlignContent.Stretch, }; bool isDeviceNarrow = App.IsSmallDevice(); if (isDeviceNarrow) { view.Direction = FlexDirection.Column; view.AlignItems = FlexAlignItems.Stretch; } else { view.JustifyContent = FlexJustify.SpaceBetween; view.AlignItems = FlexAlignItems.Center; view.Wrap = FlexWrap.Wrap; view.Direction = FlexDirection.Row; } // Caption { bool centerTextHorizontally = false; if (caption.StartsWith("^")) { centerTextHorizontally = true; caption = caption.TrimStart('^'); } var lableCaption = new Label() { Text = caption.TrimStart('#'), TextColor = Color.Black, HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = centerTextHorizontally ? TextAlignment.Center : TextAlignment.Start, VerticalTextAlignment = TextAlignment.Center, FontAttributes = bigCaption ? FontAttributes.Bold : FontAttributes.None, HeightRequest = 50, LineBreakMode = LineBreakMode.NoWrap, }; if (bigCaption) { lableCaption.FontSize *= 1.20; } FlexLayout.SetGrow(lableCaption, 1); view.Children.Add(lableCaption); } // Center text if (centerText != null) { var lableCaption = new Label() { Text = centerText, TextColor = Color.Black, HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.StartAndExpand, FontSize = 12 }; FlexLayout.SetGrow(lableCaption, 3); view.Children.Add(lableCaption); } // Value { var buttonValue = new XButton() { HorizontalOptions = LayoutOptions.EndAndExpand, //HeightRequest = 50, }; FlexLayout.SetGrow(buttonValue, 2); if (bigCaption) { buttonValue.FontSize *= 1.30; } if (value is decimal or double or float) { buttonValue.Text = ((decimal)value).ToString("C"); buttonValue.TextColor = MyColors.GetCurrencyColor((decimal)value); buttonValue.SetAsCurrenty(); }
public MainPageCS() { #region Football StackLayout footballHeader = new StackLayout { Padding = new Thickness(16), Orientation = StackOrientation.Horizontal, Children = { new Image { Margin = new Thickness(24, 0, 0, 0), HeightRequest = 35, WidthRequest = 35, VerticalOptions = LayoutOptions.Center, Source = ImageSource.FromResource("FBIOperation.Images.ball.png", typeof(MainPageCS).GetTypeInfo().Assembly) }, new Entry { BackgroundColor = Color.Transparent, Text = "Футбол", FontSize = 24, FontAttributes = FontAttributes.Bold, TextColor = Color.White, VerticalOptions = LayoutOptions.Center, WidthRequest = 180, HorizontalOptions = LayoutOptions.Start, Margin = new Thickness(14, 0, 0, 0) }, new Button { Text = "X", BorderWidth = 3, BorderColor = Color.FromHex("#FFD7CO"), TextColor = Color.FromHex("#FFD7CO"), FontAttributes = FontAttributes.Bold, HeightRequest = 40, WidthRequest = 40, CornerRadius = 20, VerticalOptions = LayoutOptions.Center, BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.EndAndExpand, Margin = new Thickness(0, 0, 24, 0) } } }; StackLayout footballStackBody = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, Children = { new Label { Text = "Итог", TextColor = Color.FromHex("#F3F3F3"), FontSize = 20, Margin = new Thickness(0, 5), HorizontalTextAlignment = TextAlignment.Center, FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.FillAndExpand }, new BoxView { BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 1.5 } } }; for (int i = 0; i < footballItogCountItems; i++) { footballStackBody.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Spacing = 0, Padding = new Thickness(0, 4), Children = { new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, TextColor = Color.FromHex("#F3F3F3") }, new Label { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Margin = new Thickness(0, 0, 26, 0), TextColor = Color.FromHex("#F3F3F3") }, new Label { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, TextColor = Color.FromHex("#F3F3F3") } } }); if (i != 9) { footballStackBody.Children.Add(new BoxView { BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 1.5 }); } } Frame footballBody = new Frame { HasShadow = false, BackgroundColor = Color.FromHex("#C6E8CB"), VerticalOptions = LayoutOptions.FillAndExpand, CornerRadius = 30, Padding = new Thickness(0), HeightRequest = 500, Content = new ScrollView { VerticalScrollBarVisibility = ScrollBarVisibility.Never, Content = footballStackBody } }; Frame footballFrame = new Frame() { Margin = Device.RuntimePlatform == Device.Android ? new Thickness(16, 16) : Device.RuntimePlatform == Device.UWP ? new Thickness(24, 16) : new Thickness(8), HeightRequest = 400, CornerRadius = 50, BackgroundColor = Color.FromHex("#9CD4AC"), Padding = new Thickness(0), Content = new StackLayout { Children = { footballHeader, footballBody } } }; FlexLayout.SetBasis(footballFrame, new FlexBasis(600)); #endregion #region Hockey Image puckImage = new Image() { Source = ImageSource.FromResource("FBIOperation.Images.puck.png", typeof(MainPageCS).GetTypeInfo().Assembly), HeightRequest = 35, WidthRequest = 35, Margin = new Thickness(40, 16, 0, 16), VerticalOptions = LayoutOptions.Center }; Grid.SetRow(puckImage, 0); Grid.SetColumn(puckImage, 0); Label hockeyHeaderLabel = new Label() { Text = "Хоккей", TextColor = Color.FromHex("#F3F3F3"), FontSize = 24, FontAttributes = FontAttributes.Bold, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(16, 16, 0, 16) }; Grid.SetRow(hockeyHeaderLabel, 0); Grid.SetColumn(hockeyHeaderLabel, 1); Switch hockeySwitch = new Switch() { IsToggled = true, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.EndAndExpand, Margin = new Thickness(0, 0, 60, 0), OnColor = Color.LightGray, ThumbColor = Color.Gray }; Grid.SetRow(hockeySwitch, 0); Grid.SetColumn(hockeySwitch, 2); Label hockeyItogLabel = new Label { Text = "Итог", TextColor = Color.FromHex("#F3F3F3"), FontSize = 20, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.FillAndExpand }; Grid.SetColumn(hockeyItogLabel, 0); Grid.SetColumnSpan(hockeyItogLabel, 3); Grid.SetRow(hockeyItogLabel, 0); Label hockeyHomeTeamLabel1 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel1, 1); Grid.SetColumn(hockeyHomeTeamLabel1, 0); Label hockeyScoreLabel1 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel1, 1); Grid.SetColumn(hockeyScoreLabel1, 1); Label hockeyGuestTeamLabel1 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel1, 1); Grid.SetColumn(hockeyGuestTeamLabel1, 2); #region Labels Label hockeyHomeTeamLabel2 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel2, 2); Grid.SetColumn(hockeyHomeTeamLabel2, 0); Label hockeyScoreLabel2 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel2, 2); Grid.SetColumn(hockeyScoreLabel2, 1); Label hockeyGuestTeamLabel2 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel2, 2); Grid.SetColumn(hockeyGuestTeamLabel2, 2); Label hockeyHomeTeamLabel3 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel3, 3); Grid.SetColumn(hockeyHomeTeamLabel3, 0); Label hockeyScoreLabel3 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel3, 3); Grid.SetColumn(hockeyScoreLabel3, 1); Label hockeyGuestTeamLabel3 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel3, 3); Grid.SetColumn(hockeyGuestTeamLabel3, 2); Label hockeyHomeTeamLabel4 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel4, 4); Grid.SetColumn(hockeyHomeTeamLabel4, 0); Label hockeyScoreLabel4 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel4, 4); Grid.SetColumn(hockeyScoreLabel4, 1); Label hockeyGuestTeamLabel4 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel4, 4); Grid.SetColumn(hockeyGuestTeamLabel4, 2); Label hockeyHomeTeamLabel5 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel5, 5); Grid.SetColumn(hockeyHomeTeamLabel5, 0); Label hockeyScoreLabel5 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel5, 5); Grid.SetColumn(hockeyScoreLabel5, 1); Label hockeyGuestTeamLabel5 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel5, 5); Grid.SetColumn(hockeyGuestTeamLabel5, 2); Label hockeyHomeTeamLabel6 = new Label { Text = "ФК Москва", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyHomeTeamLabel6, 6); Grid.SetColumn(hockeyHomeTeamLabel6, 0); Label hockeyScoreLabel6 = new Label() { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#F3F3F3"), HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("AECED8") }; Grid.SetRow(hockeyScoreLabel6, 6); Grid.SetColumn(hockeyScoreLabel6, 1); Label hockeyGuestTeamLabel6 = new Label() { Text = "Сатурн", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#AECED8"), TextColor = Color.FromHex("F3F3F3") }; Grid.SetRow(hockeyGuestTeamLabel6, 6); Grid.SetColumn(hockeyGuestTeamLabel6, 2); #endregion Grid hockeyBodyGrid = new Grid() { BackgroundColor = Color.White, RowSpacing = 1, ColumnSpacing = 0, RowDefinitions = { new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Star }, }, ColumnDefinitions = { new ColumnDefinition() { Width = GridLength.Star }, new ColumnDefinition() { Width = GridLength.Auto }, new ColumnDefinition() { Width = GridLength.Star }, }, Children = { hockeyItogLabel, hockeyHomeTeamLabel1, hockeyScoreLabel1, hockeyGuestTeamLabel1, hockeyHomeTeamLabel2, hockeyScoreLabel2, hockeyGuestTeamLabel2, hockeyHomeTeamLabel3, hockeyScoreLabel3, hockeyGuestTeamLabel3, hockeyHomeTeamLabel4, hockeyScoreLabel4, hockeyGuestTeamLabel4, hockeyHomeTeamLabel5, hockeyScoreLabel5, hockeyGuestTeamLabel5, hockeyHomeTeamLabel6, hockeyScoreLabel6, hockeyGuestTeamLabel6, } }; Frame hockeyBodyFrame = new Frame() { HasShadow = false, BackgroundColor = Color.FromHex("#AECED8"), VerticalOptions = LayoutOptions.FillAndExpand, CornerRadius = 30, Padding = new Thickness(0), HeightRequest = 500, Content = hockeyBodyGrid }; Grid.SetRow(hockeyBodyFrame, 1); Grid.SetColumn(hockeyBodyFrame, 0); Grid.SetColumnSpan(hockeyBodyFrame, 3); Grid hockeyMainGrid = new Grid { ColumnDefinitions = { new ColumnDefinition() { Width = new GridLength(75, GridUnitType.Absolute) }, new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }, }, RowDefinitions = { new RowDefinition() { Height = GridLength.Auto }, new RowDefinition() { Height = GridLength.Star }, }, Children = { puckImage, hockeyHeaderLabel, hockeySwitch, hockeyBodyFrame } }; Frame hockeyFrame = new Frame { Margin = Device.RuntimePlatform == Device.Android ? new Thickness(16, 16) : Device.RuntimePlatform == Device.UWP ? new Thickness(24, 16) : new Thickness(8), HeightRequest = 400, CornerRadius = 50, BackgroundColor = Color.FromHex("#4AA2BD"), Padding = new Thickness(0), Content = new StackLayout { Children = { hockeyMainGrid } } }; FlexLayout.SetBasis(hockeyFrame, new FlexBasis(600)); #endregion #region BasketBall FlexLayout basketballRowHolder = new FlexLayout() { Direction = FlexDirection.Column }; for (int i = 0; i < basketballItogCountItems; i++) { FlexLayout basketballRow = new FlexLayout() { Direction = FlexDirection.Row, JustifyContent = FlexJustify.SpaceEvenly, AlignItems = FlexAlignItems.Center, Children = { new Label { Text = "ФК Москва", TextColor = Color.FromHex("#F3F3F3") }, new Label { Text = "0 : 1", FontSize = 22, FontAttributes = FontAttributes.Bold, Margin = new Thickness(0, 0, 26, 0), TextColor = Color.FromHex("#F3F3F3") }, new Label { Text = "Сатурн", TextColor = Color.FromHex("#F3F3F3") } } }; FlexLayout.SetBasis(basketballRow, new FlexBasis(50)); BoxView rowSeparator = new BoxView() { BackgroundColor = Color.White }; FlexLayout.SetAlignSelf(rowSeparator, FlexAlignSelf.Stretch); FlexLayout.SetBasis(rowSeparator, 2f); basketballRowHolder.Children.Add(basketballRow); basketballRowHolder.Children.Add(rowSeparator); } BoxView basketBallSeparator0 = new BoxView() { BackgroundColor = Color.White }; FlexLayout.SetAlignSelf(basketBallSeparator0, FlexAlignSelf.Stretch); FlexLayout.SetBasis(basketBallSeparator0, 2f); Label basketballNameLabel = new Label() { Text = "Итог", TextColor = Color.FromHex("#F3F3F3"), FontSize = 20, Margin = new Thickness(0, 10), FontAttributes = FontAttributes.Bold }; FlexLayout.SetAlignSelf(basketballNameLabel, FlexAlignSelf.Center); Frame basketballBodyFrame = new Frame() { HasShadow = false, BackgroundColor = Color.FromHex("#F2B18C"), CornerRadius = 30, Padding = new Thickness(0), Content = new FlexLayout() { Direction = FlexDirection.Column, Children = { basketballNameLabel, basketBallSeparator0, new ScrollView() { Content = basketballRowHolder } } } }; FlexLayout.SetGrow(basketballBodyFrame, 1); Label basketballHeaderLabel = new Label() { Text = "Баскетбол", FontSize = 24, FontAttributes = FontAttributes.Bold, TextColor = Color.White, Margin = new Thickness(16, 16, 0, 16) }; FlexLayout.SetGrow(basketballHeaderLabel, 1); FlexLayout basketballHeader = new FlexLayout() { Direction = FlexDirection.Row, AlignItems = FlexAlignItems.Start, JustifyContent = FlexJustify.Start, Children = { new Image() { Source = ImageSource.FromResource("FBIOperation.Images.bsball.png", typeof(MainPageCS).GetTypeInfo().Assembly), Margin = new Thickness(40, 16, 0, 16), HeightRequest = 35, WidthRequest = 35 }, basketballHeaderLabel, new CheckBox() { IsChecked = false, BackgroundColor = Color.Transparent, Color = Color.FromHex("#F2B18C"), Margin = new Thickness(0, 16, 40, 16) } } }; FlexLayout.SetBasis(basketballHeader, new FlexBasis(130)); Frame basketBallFrame = new Frame() { Margin = Device.RuntimePlatform == Device.Android ? new Thickness(16, 16) : Device.RuntimePlatform == Device.UWP ? new Thickness(24, 16) : new Thickness(8), HeightRequest = 400, CornerRadius = 50, Padding = new Thickness(0), Content = new FlexLayout() { Direction = FlexDirection.Column, BackgroundColor = Color.FromHex("#E5824B"), JustifyContent = FlexJustify.Start, Wrap = FlexWrap.NoWrap, AlignItems = FlexAlignItems.Start, Children = { basketballHeader, basketballBodyFrame } } }; FlexLayout.SetBasis(basketBallFrame, new FlexBasis(600)); #endregion Content = new ScrollView { Content = new FlexLayout { Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, AlignItems = FlexAlignItems.Start, AlignContent = FlexAlignContent.SpaceEvenly, JustifyContent = FlexJustify.SpaceAround, Margin = Device.RuntimePlatform == Device.Android ? new Thickness(8) : Device.RuntimePlatform == Device.UWP ? new Thickness(48) : new Thickness(8), Children = { footballFrame, hockeyFrame, basketBallFrame } } }; }
public DiscountDetailPage(DiscountDetailData discountDetailData) : base(typeof(DiscountDetailViewModel), typeof(DiscountDetailContentUI)) { BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(); Content.BackgroundColor = MainStyles.MainLightBackgroundColor.FromResources <Color>(); var loadingColor = MainStyles.LoadingColor.FromResources <Color>(); LoadingActivityIndicator.Color = loadingColor; LoadingActivityText.TextColor = loadingColor; 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 Label percent const int sizeImgLabel = 60; var imgLabel = new Image { HeightRequest = sizeImgLabel, WidthRequest = sizeImgLabel, Source = contentUI.ImgPercentLabel }; var labelLayout = new AbsoluteLayout { InputTransparent = true }; AbsoluteLayout.SetLayoutFlags(imgLabel, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(imgLabel, new Rectangle(0f, 0f, 1f, 1f)); labelLayout.Children.Add(imgLabel); var spanDiscountPercent = new Span { Style = LabelStyles.LabelPercentStyle.FromResources <Style>() }; spanDiscountPercent.SetBinding(Span.TextProperty, nameof(DiscountDetailViewModel.DiscountPercent)); var spanDiscountType = new Span { Style = LabelStyles.LabelPercentSymbolStyle.FromResources <Style>() }; spanDiscountType.SetBinding(Span.TextProperty, nameof(DiscountDetailViewModel.DiscountType)); 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) }; const int sizeWebAddress = 40; foreach (var webAddress in viewModel.WebAddresses) { var imgWebAddress = new Image { Source = webAddress.Type.GetWebAddressIcon(), Margin = new Thickness(0, 0, 5, 5), WidthRequest = sizeWebAddress, HeightRequest = sizeWebAddress }; var tapWebAddress = new TapGestureRecognizer { CommandParameter = webAddress.Url }; tapWebAddress.Tapped += viewModel.TxtUrlAddress_Click; imgWebAddress.GestureRecognizers.Add(tapWebAddress); flexCategories.Children.Add(imgWebAddress); } 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 Carousel images var carouselView = new CarouselViewControl { Orientation = CarouselViewOrientation.Horizontal, ItemTemplate = new DataTemplate(typeof(GalleryImageItemTemplate)), CurrentPageIndicatorTintColor = MainStyles.MainBackgroundColor.FromResources <Color>() }; carouselView.SetBinding(CarouselViewControl.ItemsSourceProperty, nameof(DiscountDetailViewModel.GalleryImages)); carouselView.SetBinding(CarouselViewControl.ShowIndicatorsProperty, nameof(DiscountDetailViewModel.HasGalleryImages)); carouselView.SetBinding(CarouselViewControl.IsSwipeEnabledProperty, nameof(DiscountDetailViewModel.HasGalleryImages)); var carouselLayout = new RelativeLayout { VerticalOptions = LayoutOptions.Start }; carouselLayout.Children.Add(carouselView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => Device.Info.CurrentOrientation.IsPortrait() ? parent.Width * 0.5625 : Device.Idiom == TargetIdiom.Phone ? 200 : 400)); carouselLayout.Children.Add(labelLayout, Constraint.RelativeToView(carouselView, (parent, view) => view.Width - sizeImgLabel - 5), Constraint.RelativeToView(carouselView, (parent, view) => view.Height - sizeImgLabel - 5)); #endregion #region Name company var txtPartnerName = new Label { Style = LabelStyles.DetailTitleStyle.FromResources <Style>(), Margin = new Thickness(20, 0) }; txtPartnerName.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.NameCompany)); #endregion #region Description var txtDescription = new Label { Style = LabelStyles.DescriptionStyle.FromResources <Style>(), Margin = new Thickness(20, 10, 20, 0), LineBreakMode = LineBreakMode.WordWrap }; txtDescription.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.Description)); #endregion #region Rating view var ratingView = new RatingView { Style = LabelStyles.RatingStyle.FromResources <Style>() }; ratingView.SetBinding(RatingView.ValueProperty, nameof(DiscountDetailViewModel.UserRating)); var ratingLabel = new Label { Style = LabelStyles.DescriptionStyle.FromResources <Style>(), VerticalOptions = LayoutOptions.End }; ratingLabel.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.RatingString)); ratingLabel.SetBinding(IsVisibleProperty, nameof(DiscountDetailViewModel.IsDiscountRatingAvailable)); var activityIndicator = new ActivityIndicator { Color = Color.FromHex("444"), HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, WidthRequest = 20, HeightRequest = 20 }; activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(DiscountDetailViewModel.IsLoadingRating)); activityIndicator.SetBinding(IsVisibleProperty, nameof(DiscountDetailViewModel.IsLoadingRating)); var stackRating = new StackLayout { Orientation = StackOrientation.Horizontal, Margin = new Thickness(20, 0), Spacing = 10, Children = { ratingView, ratingLabel, activityIndicator } }; #endregion var discountLayout = new StackLayout { Spacing = 0, Orientation = StackOrientation.Vertical, Children = { carouselLayout, flexCategories, txtPartnerName, stackRating, txtDescription } }; foreach (var brachItem in viewModel.BranchItems) { var view = new BranchInfoViewTemplate(contentUI, viewModel) { 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); }