您可以更改项目中所有工具的文本颜色吗?

Can you change the textcolor of all the tools in your project?

你能更改项目中所有文本的文本颜色吗?我的意思是不是通过绑定或什么,只是通过设置默认颜色或者我真的需要更改每个 label/entry/button 等的 属性 等...?

在 Xamarin 中,您可以创建全局样式。 来自 documentation:

Styles can be made available globally by adding them to the application's resource dictionary. This helps to avoid duplication of styles across pages or controls.

一种方法是使用样式和目标 label/entry/button 等等

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

详情请参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/

另一种方法是将颜色设置为资源。

设置资源:

 <Application.Resources>
    <!-- Colors -->
    <Color x:Key="NormalTextColor">Black</Color>
</Application.Resources>

用法:

   <Label Text="Hello"
                   TextColor="{StaticResource NormalTextColor}"
                   FontAttributes="Bold" />

详情请参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/resource-dictionaries

喜欢 TheTanic 的回答。 例如:

App.xaml 中有一个 Style 用于名称为 BLabel 的标签。

<Style x:Key="BLabel" TargetType="Label">
    <Setter Property="TextColor"  Value="#A7ADB1" />
    <Setter Property="HorizontalOptions" Value="Start" />
    <Setter Property="VerticalOptions" Value="Center" />
</Style>

你可以这样使用它,在 MainPage.xaml.

 <Label
   Grid.Row="4"
   Grid.Column="1"
   Style="{StaticResource BLabel}"
   Text="BB 3" />

但您还可以添加更多内容,例如:

 <Setter Property="WidthRequest" Value="150" />
    <Setter Property="HeightRequest" Value="40" />
    <Setter Property="FontSize" Value="Small" />
    <Setter Property="BorderWidth" Value="1" />
    <Setter Property="BackgroundColor" Value="Red" />
    <Setter Property="HorizontalOptions" Value="Center" />
    <Setter Property="TextTransform" Value="None" />

还有更多....

不仅用于标签,还用于按钮等

这是 StaticResource 的示例,但您也可以使用 DynamicResource 来更改颜色等

https://www.youtube.com/watch?v=Se0yF5JXk70&ab_channel=JamesMontemagno