Samantha J T Star
Samantha J T Star

Reputation: 32798

Is there a way that I can add the ColumnDefinitions into the <grid>

My code looks like this:

<Grid VerticalOptions="CenterAndExpand" Padding="20, 0">
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="Auto" />
   </Grid.ColumnDefinitions>
   <local:LabelBodyRendererClass HorizontalOptions="StartAndExpand" Text="Show Subcategory" YAlign="Center" XAlign="Center" />
   <Switch x:Name="swtSwitch" Grid.Column="1" Toggled="SwtSwitch" VerticalOptions="Center" HorizontalOptions="End" />
</Grid>

Is there a way that I can add the ColumnDefinitions into the element? My IDE is showing it's an option but I don't know how to specify them.

Upvotes: 0

Views: 37

Answers (1)

Gerald Versluis
Gerald Versluis

Reputation: 34013

I don't think you can define it as an attribute. And if you could, it would wreck your readability. Because ColumnDefinition is a complex type, you would have to type the string representation of it, as an array, inside an attribute.

If you want to clean your code, create your own, custom grid which has the columns predefined, but then you would have to expose views as properties, to fill your column. So, you would only save a few lines of the column definitions.

Upvotes: 1

Related Questions