Home > Software design >  Style was not found XAML
Style was not found XAML

Time:11-03

So I have my App.xaml :

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Fitness_App.App">
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="WorkoutStyle" TargetType="Label">
              <Setter Property="FontSize" Value="28"/>
              <Setter Property="FontFamily" Value="BebasNeue"/>
              <Setter Property="TextColor" Value="Wheat"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Here I declared a style GLOBALLY as far as I've read the microsoft documentation.However , when in another xaml file I do this:

 <Label Style= "{StaticResource WorkoutStyle}"

It says that WorkoutStyle could not be found.Any idea why?

CodePudding user response:

Declaration is correct. Just Remove obj and bin of targeted project and do a rebuild. This will solve the issue.

CodePudding user response:

This is working

 <Application.Resources>
    <ResourceDictionary>
        <Style x:Key="WorkoutStyle" TargetType="Label">
          <Setter Property="FontSize" Value="28"/>
          <Setter Property="TextColor" Value="Wheat"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

This line is not good

 <Setter Property="FontFamily" Value="BebasNeue"/>

Your FontFamily is wrong look here for an example , change it with your font

 <Style x:Key="NormalFont" TargetType="Label">
    <Setter Property="FontFamily" Value="NunitoSans-Regular.ttf#NunitoSans-Regular.ttf"/>
</Style>   

Explaned here https://www.serkanseker.com/xamarin-forms-custom-font-family/

  • Related