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

Label WordWrap within Grid Cell

$
0
0

Hi, can anyone help me on matter as below ?

I unable to wordwrap nicely a label within a grid cell ?

Grid grid = new Grid
            {
                VerticalOptions = LayoutOptions.FillAndExpand,

                RowDefinitions = 
                {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },                   
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto }                  
                },
                ColumnDefinitions = 
                {
                    new ColumnDefinition { Width = GridLength.Auto },
                    new ColumnDefinition { Width = GridLength.Auto }              
                }
            };

 Func<string, Label> CreateLabelWordWrap = (string source) =>
            {
                Label label = new Label
                {
                    FontSize          = 20,
                    FontAttributes    = Xamarin.Forms.FontAttributes.Bold,
                    XAlign            = TextAlignment.Start,
                    LineBreakMode     = LineBreakMode.WordWrap,
                    HorizontalOptions = LayoutOptions.Fill
                };
                label.SizeChanged += label_SizeChanged;
                label.SetBinding(Label.TextProperty, source);
                return label;
            };

void label_SizeChanged(object sender, EventArgs e)
        {
            Label lb        = ((Label)sender);
            lb.WidthRequest = lb.Text.Length;
        }

It will keep appear extra empty space between next Row (as image show in attached file).
How should I improve it ?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>