I have been watching some online xamarin forms tutorials. All of them suggest using the resource dictionary for global rules such as styles. However I have noticed a lot of risks of mistakes. Consider the following example:
In the dictionary I mention
<Style TargetType="Label" x:Key="lblStyle">
<Property="FontAttributes" Value="Bold" />
<Setter Property="FontSize" Value="30" />
</Style>
Then I can use it as
<Label Text="My Text" Style="{StaticResource lblStyle}" />
However when assigning to the dictionary, I only get intellisense some key words and when implementing on the label I don't get intellisense for the key lblStyle
. Also I don't know if I have entered anything wrong as it is mostly not caught in compile time. I do understand why no intellisense, but I found the following easier to code and it does the same
First I create a class
public class MyLabel : Label
{
public MyLabel()
{
FontAttributes = FontAttributes.Bold;
FontSize = 30;
}
}
I can then declare in xml and use following:
<Components:MyLabel Text="My Text" />
In terms of coding, the second way seems to be better in every way. What I do not understand is, why all the tutorials recommend we use the resource dictionary? Is there some serious performance advantage that is worth all the weak typing?