Hi,
Is it possible to give all my chips the same width? if yes, how can this be achieved, and is this maybe also possible by using a percentage of the container?
Thanks
Kris
|
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="chipStyle" TargetType="buttons:SfChip">
<Setter Property="WidthRequest" Value="100"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout x:Name="layout" Orientation="Horizontal" VerticalOptions="Center"
SizeChanged="layout_SizeChanged">
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Extra Small"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Small"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Medium"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Large"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Extra Large"/>
</StackLayout>
</ContentPage.Content> |
|
double percentage = 20;
…. private void layout_SizeChanged(object sender, EventArgs e)
{
double containerWidth = layout.Width;
double chipWidth = (containerWidth / 100) * percentage;
var buttonStyle = new Style(typeof(SfChip));
buttonStyle.Setters.Add(new Setter() { Property = SfChip.WidthRequestProperty,
Value = chipWidth });
Resources["chipStyle"] = buttonStyle;
} |
Hi,
Thank you for this example. I have one extra addition, could this be wrapped across multiple lines?
Regards
Kris
|
<StackLayout x:Name="layout" SizeChanged="layout_SizeChanged">
<FlexLayout HorizontalOptions="Start"
VerticalOptions="Center"
Direction="Row"
Wrap="Wrap"
JustifyContent="Start"
AlignContent="Start"
AlignItems="Start">
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Extra Small"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Small"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Medium"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Large"/>
<buttons:SfChip Style="{DynamicResource chipStyle}" Text="Extra Large"/>
</FlexLayout>
</StackLayout> |