static Grid CreateRepositoryDataTemplate() { const int circleImageHeight = 90; const int emojiColumnSize = 15; const int countColumnSize = 30; var image = new CircleImage { HeightRequest = circleImageHeight, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, }; image.SetBinding(CircleImage.SourceProperty, nameof(Repository.OwnerAvatarUrl)); var repositoryNameLabel = new DarkBlueLabel { FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Start, LineBreakMode = LineBreakMode.TailTruncation, HorizontalOptions = LayoutOptions.FillAndExpand }; repositoryNameLabel.SetBinding(Label.TextProperty, nameof(Repository.Name)); var repositoryDescriptionLabel = new DarkBlueLabel { FontSize = _smallFontSize, LineBreakMode = LineBreakMode.WordWrap, VerticalTextAlignment = TextAlignment.Start, FontAttributes = FontAttributes.Italic }; repositoryDescriptionLabel.SetBinding(Label.TextProperty, nameof(Repository.Description)); var starsSVGImage = new SmallNavyBlueSVGImage("star.svg"); var starsCountLabel = new DarkBlueLabel(_smallFontSize - 1); starsCountLabel.SetBinding(Label.TextProperty, nameof(Repository.StarCount)); var forksSVGImage = new SmallNavyBlueSVGImage("repo_forked.svg"); var forksCountLabel = new DarkBlueLabel(_smallFontSize - 1); forksCountLabel.SetBinding(Label.TextProperty, nameof(Repository.ForkCount)); var issuesSVGImage = new SmallNavyBlueSVGImage("issue_opened.svg"); var issuesCountLabel = new DarkBlueLabel(_smallFontSize - 1); issuesCountLabel.SetBinding(Label.TextProperty, nameof(Repository.IssuesCount)); var grid = new Grid { BackgroundColor = Color.Transparent, Padding = new Thickness(2, 0, 5, 0), RowSpacing = 2, ColumnSpacing = 3, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.StartAndExpand, RowDefinitions = { new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(20, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(45, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(_smallFontSize + 2, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(circleImageHeight, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(2, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(emojiColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(countColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(emojiColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(countColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(emojiColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(countColumnSize, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; grid.Children.Add(image, 0, 0); Grid.SetRowSpan(image, 6); grid.Children.Add(repositoryNameLabel, 2, 1); Grid.SetColumnSpan(repositoryNameLabel, 7); grid.Children.Add(repositoryDescriptionLabel, 2, 2); Grid.SetColumnSpan(repositoryDescriptionLabel, 7); grid.Children.Add(starsSVGImage, 2, 4); grid.Children.Add(starsCountLabel, 3, 4); grid.Children.Add(forksSVGImage, 4, 4); grid.Children.Add(forksCountLabel, 5, 4); grid.Children.Add(issuesSVGImage, 6, 4); grid.Children.Add(issuesCountLabel, 7, 4); return(grid); }
static Layout CreateImageLayout(DogImagesModel dogImagesModel) { const int circleImageHeight = 90; const int fontSize = 16; const int padding = 5; var avatarImage = new CircleImage { Source = dogImagesModel.AvatarUrl, HeightRequest = circleImageHeight, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, Aspect = Aspect.AspectFill }; var dogNameTitleLabel = new DarkBlueLabel { Text = dogImagesModel.Title, FontSize = fontSize * 4 / 3, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Start, LineBreakMode = LineBreakMode.TailTruncation, HorizontalOptions = LayoutOptions.FillAndExpand }; var dogBreedLabel = new DarkBlueLabel(fontSize) { Text = $"🐶 {dogImagesModel.Breed}" }; var coatColorLabel = new DarkBlueLabel(fontSize) { Text = $"🎨 {dogImagesModel.CoatColor}" }; var birthDateLabel = new DarkBlueLabel(fontSize) { Text = $"🎂 {dogImagesModel.BirthDate?.ToString("MMMM dd yyyy") ?? "Unknown"}" }; var contentGrid = new Grid { BackgroundColor = Color.Transparent, RowSpacing = 2, ColumnSpacing = 3, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.StartAndExpand, RowDefinitions = { new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(fontSize * 4 / 3 + 5, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(fontSize + 5, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(fontSize + 5, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(fontSize + 5, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(circleImageHeight, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(2, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; contentGrid.Children.Add(avatarImage, 0, 0); Grid.SetRowSpan(avatarImage, 6); contentGrid.Children.Add(dogNameTitleLabel, 2, 1); contentGrid.Children.Add(dogBreedLabel, 2, 2); contentGrid.Children.Add(coatColorLabel, 2, 3); contentGrid.Children.Add(birthDateLabel, 2, 4); var contentFrame = new Frame { CornerRadius = 7, Padding = new Thickness(5, 10), BackgroundColor = Color.FromHex("8BB6D6"), Content = contentGrid }; var rowGrid = new Grid { RowDefinitions = { new RowDefinition { Height = new GridLength(padding, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(padding / 2, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(padding / 2, GridUnitType.Absolute) } } }; rowGrid.Children.Add(contentFrame, 1, 1); return(rowGrid); }