您可以更改專案中所有文本的文本顏色嗎?我的意思不是通過系結或什么,只是通過設定默認顏色還是我真的需要更改每個標簽/條目/按鈕等的屬性......?
uj5u.com熱心網友回復:
在 Xamarin 中,您可以創建全域樣式。從檔案:
樣式可以通過將它們添加到應用程式的資源字典來全域使用。這有助于避免跨頁面或控制元件的樣式重復。
uj5u.com熱心網友回復:
一種方法是將樣式和目標用于標簽/條目/按鈕等。
<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
uj5u.com熱心網友回復:
就像 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/388632.html
