【问题标题】:Xamarin: How do I override a label style class for all labels?Xamarin:如何覆盖所有标签的标签样式类?
【发布时间】:2019-09-03 10:59:00
【问题描述】:

在 nuget 包中有一个 Xaml 文件,其中包含:

<Style x:Key="LabelBase" TargetType="Label">
    <Setter Property="TextColor" Value="Green" />
</Style>

<Style
    BasedOn="{StaticResource LabelBase}"
    Class="Primary"
    TargetType="Label">
</Style>

在当前项目 App.xaml 我有:

<Style TargetType="Label">
   <Setter Property="TextColor" Value="Red" />
</Style>

ResourceDictionary 有 MergedWith="XAMLFILE",nuget .xaml 文件 ResourceDictionary。

在页面的 AbsoluteLayout 中我有一个标签

<Label
    Grid.Row="0"
    FontSize="45"
    HorizontalTextAlignment="Center"
    StyleClass="Primary"
    Text="Text Value"
    VerticalOptions="Center" />

如何在我的项目 App.Xaml 中覆盖 Primary StyleClass 以使文本颜色继承红色而不创建新的 styleclass?

【问题讨论】:

    标签: xml xamarin xamarin.forms xamarin.android


    【解决方案1】:

    如果您希望将该主题应用于所有标签,只需删除该类即可:

    <Style
    BasedOn="{StaticResource LabelBase}"
    TargetType="Label">
    </Style>
    

    请注意您没有密钥并且样式在 APP.xaml 中

    祝你好运

    随时恢复。

    【讨论】:

    • 我无法从 nuget 包中删除该类,也无法更改 App.xaml 文件。我想知道是否有办法在当前项目的 App.xaml 文件中覆盖该类。
    • 这是哪个 NuGet 包?在 NuGet 中包含 App.xaml 并不常见。
    • 你在说什么 NuGet 包?
    • 这是一个内部 nuget 包。
    • 然后把那个资源字典合并到这个项目中然后使用docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/…
    猜你喜欢
    • 2019-03-04
    • 2020-01-01
    • 1970-01-01
    • 2019-12-10
    • 2021-12-07
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 2018-11-14
    相关资源
    最近更新 更多