I want to build few pages with specific Padding in sytacklayout. I do not want to wrote it in every pages. And its not good design considering if I want to change it in future. Is there a way to define padding in static resource? So that I can define it in one place App.xml
and use it in other pages.
I have tried
<ContentPage.Resources>
<ResourceDictionary>
<x:String x:Key="padding">45, 0, 45, 0</x:String>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout Padding="{StaticResource padding}">
<Label Text="{StaticResource padding}"/>
</StackLayout>
As said, you should use Thickness
. In addition, for setting your resource at the Application level, put it in your App.xaml
file:
<Application ...>
<Application.Resources>
<ResourceDictionary>
<Thickness x:Key="padding">45,0, 45, 0</Thickness>
// some others resources...
</ResourceDictionary>
</Application.Resources>
</Application>
Then call it from your different pages:
<ContentPage>
<StackLayout Padding="{StaticResource padding}">
<Label Text="{StaticResource padding}"/>
</StackLayout>
...
link to documentation
Hope it helps!
Just use Thickness
instead of a string
:
<ContentPage.Resources>
<ResourceDictionary>
<Thickness x:Key="padding">45,0</Thickness>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout Padding="{StaticResource padding}">
<Label Text="{StaticResource padding}"/>
</StackLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With