Reputation: 141
I want to change the BorderWidth property of multiple buttons using classid. Is it possible in xamarin forms. Something like classid.BorderWidth = borderwidth
Upvotes: 0
Views: 882
Reputation: 530
In Xamarin Forms, to change the style of multiple controls of the same type, you have to use Style
classes.
You can define a style at Application
level or page
level. Here is a style definition at page level:
<ContentPage ....>
<ContentPage.Resources>
<Style x:Key="myBigButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="Black" />
<Setter Property="BorderThickness" Value="10" />
</Style>
</ContentPage.Resources>
. . .
To apply the style:
<Button x:Name="button1" Style="{StaticResource myBigButtonStyle}" ... />
But if you want to apply this style to ALL the buttons of your page, just remove the resource button style KEY:
<Style TargetType="Button">
<Setter Property="Foreground" Value="Black" />
<Setter Property="BorderThickness" Value="10" />
</Style>
then, do not apply any style to your buttons:
<Button x:Name="button1" ... />
All the style
class documentation can be found here:
Microsoft styles documentation
Syntax is not the same as html. But in the latest versions of Xamarin you can use CSS files to apply styles. But this option is still limited: Using CSS files with Xamarin Forms documentation
Upvotes: 2