To use styles for your custom usercontrol, you have to define the styles TargetType property with an x:Type in your resource dictionary.
<ResourceDictionary
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:buttons="clr-namespace:AnAwesomeApp.Controls.Buttons"
x:Class="AnAwesomeApp.Resources.Styles">
Declare the clr-namespace where your custom usercontrol lives.
<Style
x:Key="BlueButtonStyle"
TargetType="{x:Type buttons:ColoredButton}">
<Setter
Property="TextColor"
Value="White" />
<Setter
Property="Color"
Value="{AppThemeBinding Dark=#2325A6, Light=#61BAFF}" />
<Setter
Property="FontFamily"
Value="Nunito" />
</Style>
Set the target type with x:Type.
And boom, done!
1 thought on “Xamarin.Forms : Using styles on custom UserControls”