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

Setting column span for button variable

$
0
0

I have created a grid in my Xamarin application which has 4 rows and 24 columns.

I have 12 buttons that use the same properties, so to save myself creating all 12 separately, I have done it like this

var functionButton = new Style(typeof(Button))
     {
        Setters = {
                new Setter { Property = BackgroundColorProperty, Value = Color.FromHex ("#F0E68C") },
                new Setter { Property = Button.TextColorProperty, Value = Color.Black },
                new Setter { Property = Button.CornerRadiusProperty, Value = 0 },
                new Setter { Property = Button.FontSizeProperty, Value = 10 }
        }
      };

then add them to the grid as below

controlGrid.Children.Add(new Button { Text = "End" + Environment.NewLine + "Sale", Style = functionButton }, 0, 0);
controlGrid.Children.Add(new Button { Text = "Repeat" + Environment.NewLine + "  Last", Style = functionButton }, 1, 0);
controlGrid.Children.Add(new Button { Text = "Void" + Environment.NewLine + "Line", Style = functionButton }, 2, 0);
and so on, until all 12 have been added.

However, I want each button to take up 2 columns.

Usually, if I'd created the buttons separately I could use Grid.SetColumnSpan(Button1, 2);

But that doesn't seem very efficient, as I'd need to create all 12 buttons separately. Is there another way that I can set the column span using this method of creating the buttons that I've currently got?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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