I am new to dotnet maui and I can't figuring out how to use the styles defined in the Styles.xaml sheet in the c# markup code.
When I use the following code, my application crashes
new Label
{
Text = "Hello, World!",
Style = (Style)Application.Current.Resources["TitleLabel"]
}
The style exists in the stylesheet:
<Style TargetType="Label" x:Key="TitleLabel"\>
<Setter Property="FontFamily" Value="Montserrat" /\>
<Setter Property="FontSize" Value="20" /\>
<Setter Property="FontAttributes" Value="None" /\>
<Setter Property="TextColor" Value="{StaticResource Black}" /\>
</Style\>
So how do I get this style to work with my c# markup code?
I was able to access the Colors.xaml file with the following if-statement:
if (App.Current.Resources.TryGetValue("ReadTag", out var colorvalue))
StatusTagColor = (Color)colorvalue;