【问题标题】:Style was not found XAML未找到样式 XAML
【发布时间】:2021-12-16 11:32:48
【问题描述】:

所以我有我的 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>

就我阅读微软文档而言,我在这里声明了一种样式 GLOBALLY。但是,当在另一个 xaml 文件中我这样做时:

 <Label Style= "{StaticResource WorkoutStyle}"

它说找不到 WorkoutStyle。知道为什么吗?

【问题讨论】:

  • 你建了吗?

标签: c# xaml xamarin xamarin.forms styles


【解决方案1】:

声明正确。只需删除目标项目的 obj 和 bin 并进行重建。 这将解决问题。

【讨论】:

    【解决方案2】:

    这是有效的

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

    这条线不好

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

    你的 FontFamily 是错误的,看看这里的例子,用你的字体改变它

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

    在这里解释 https://www.serkanseker.com/xamarin-forms-custom-font-family/

    【讨论】:

    • 关于这个问题的任何更新,你解决了吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多