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

Stacklayout Label Widthrequest not working properly?

$
0
0

Hi everybody,

I really have troubles with formatting lists with custom CellViews properly. Let's assume I want to have a List with two columns (everyone is a label, basically) and the first label should have the same with in every row - as we all know this from tables ;-)
So I tried to use a "WidthRequest=100" on the first label.

This is the whole simple code for the layout

    public ProjectViewCell(){

        var lblProjectNumber = new Label{ HorizontalOptions = LayoutOptions.Start, WidthRequest = 100 , BackgroundColor=Color.Blue};
        var lblProjectName = new Label{ HorizontalOptions = LayoutOptions.Fill, LineBreakMode=LineBreakMode.TailTruncation };

        lblProjectNumber.SetBinding (Label.TextProperty, "ProjectNumber");
        lblProjectName.SetBinding (Label.TextProperty, "ProjectName");

        this.View = new StackLayout () {
            Orientation=StackOrientation.Horizontal,
            Children = {
                lblProjectNumber,
                lblProjectName
            }
        };
    }

But this results in NOT equally sized labels over all rows. (see attached screenshot). The length of the second text (right label) seems to have an impact on the size of the first label.

Any Ideas how I get this done without setting the width request of the second label too? I would not like to do that because then my app only looks nice in one special resolution.

Thank you!


Viewing all articles
Browse latest Browse all 58056

Trending Articles