Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

.EndAndExpand is aligning with end of stack above

$
0
0

I am trying to create a simple ViewCell for displaying basic file information. To the left is an icon depicting the type of file. On top is the file name and below the filename is a date (should be at start) and to the right (all the way at the end of the cell) should be the file size. What I'm seeing is the file size is aligning with the end of the filename, not the far right of the cell. The following is the code for the cell:


public class FileCell : ViewCell
    {
        public FileCell()
        {
            var image = new Image { HorizontalOptions = LayoutOptions.Start };
            image.SetBinding (Image.SourceProperty, new Binding("FileType", converter: new FileTypeToIconConverter()));
            image.WidthRequest = 16;
            image.HeightRequest = 16;

            var imageStack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                Children = {
                    image
                }
            };

            var nameLabel = new Label {
                TextColor = Color.Black,
                Font = Font.SystemFontOfSize(NamedSize.Small),
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            nameLabel.SetBinding(Label.TextProperty, "Name");

            var nameStack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Children = {
                    nameLabel
                }
            };

            var dateLabel = new Label {
                TextColor = Color.FromHex("#3999D5"),
                Font = Font.SystemFontOfSize(NamedSize.Micro),
                HorizontalOptions = LayoutOptions.StartAndExpand
            };
            dateLabel.SetBinding(Label.TextProperty, "Modification");

            var sizeLabel = new Label {
                TextColor = Color.FromHex("#3999D5"),
                Font = Font.SystemFontOfSize(NamedSize.Micro, FontAttributes.Bold),
                HorizontalOptions = LayoutOptions.EndAndExpand
            };
            sizeLabel.SetBinding(Label.TextProperty, new Binding("FileSize", converter: new LongToSizeStringConverter()));

            var detailStack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                Children = {
                    dateLabel,
                    sizeLabel
                }
            };

            var fileStack = new StackLayout {
                Orientation = StackOrientation.Vertical,
                Children = {
                    nameStack,
                    detailStack
                }
            };


            var cellStack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                Padding = new Thickness(4,0,4,0),
                Children = {
                    imageStack,
                    fileStack
                }
            };

            View = cellStack;
        }
    }

Viewing all articles
Browse latest Browse all 58056

Trending Articles