xamarinxamarin.formsmonotouch.dialog

Xamarin.Forms Listview with 2 line label?


I'm converting a MonoTouch.Dialog app to Xamarin.Forms.

I have a Cell in a ListView and that has a "Detail" line that should be 2 lines long, and should truncate the tail after that.

        var lblDetail = new Label
        {
            LineBreakMode = LineBreakMode.TailTruncation,
            Text = "a really long string that should show 2 lines then ..."
        };

How do I set something like, "Lines = 2"


Solution

  • You might want to customize ListView:

        <ListView x:Name="ListMenu" ItemsSource="{Binding _YourItems_}" >
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <ViewCell.View>
                  <StackLayout Orientation="Horizontal">
                    <Label Text="{Binding _YourText_}" TextColor="Black" />
                  </StackLayout>
                </ViewCell.View>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
    

    even if text not fit one line, it will wrap automatically.