Xamarin Forms - 设置默认 TextColor

MrS*_*nic 6 xaml xamarin xamarin.forms

有没有办法将所有包含文本的页面元素的默认文本颜色设置为特定颜色?

我需要为每个包含文本的元素设置“TextColor”属性,这对我来说没有意义。

谢谢!

Den*_*rab 6

您可以在 App.xaml 中设置包含文本的元素的样式。这将为您在应用程序中使用的所有标签、按钮等设置 TextColor:

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

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

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

    <Style TargetType="Editor">
        <Setter Property="TextColor" Value="Red" />
    </Style>
...
Run Code Online (Sandbox Code Playgroud)

不幸的是,您必须为所有包含文本的视觉元素添加新的样式标签。不久前我一直在寻找一种更清晰的方法来定义所有带有文本的元素的样式。但这似乎是最干净的方法......

希望 Xamarin.Forms 能够添加一种更通用的方式来处理样式。