所以我制作了以下標簽和框架:
//Frames
private readonly Frame _frame1 = new Frame
{
BorderColor = Colors.Black,
Padding = new Thickness(1),
BackgroundColor = Colors.Gray
};
private readonly Frame _frame2 = new Frame
{
BorderColor = Colors.Black,
Padding = new Thickness(1),
BackgroundColor = Colors.Gray
};
private readonly Frame _frame3 = new Frame
{
BorderColor = Colors.Black,
Padding = new Thickness(1),
BackgroundColor = Colors.Gray
};
//Labels
private readonly Label _label1 = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
TextColor = Colors.Black,
Padding = 5
};
private readonly Label _label2 = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
TextColor = Colors.Black,
Padding = 5
};
private readonly Label _label3 = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
TextColor = Colors.Black,
Padding = 5
};
如您所見,在制作新標簽時,我會多次設定文本顏色、填充和背景顏色等內容。我認為這可以通過在“標準”標簽/框架上定義所有這些屬性來變得更漂亮(不確定正確的詞是什么)。但基本上,當我使用框架或標簽時,我總是希望應用這些屬性。
有人知道怎么做嗎?我希望你能理解我想要達到的目標哈哈,提前謝謝!
uj5u.com熱心網友回復:
隱式樣式是一種方法。在您的 App.xaml 檔案中:
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Frame">
<Setter Property="BorderColor" Value="Black" />
<Setter Property="BackgroundColor" Value="Gray" />
<Setter Property="Padding" Value="1" />
</Style>
<Style TargetType="Label">
<Setter Property="FontSize" Value="Small" />
<Setter Property="TextColor" Value="Black" />
<Setter Property="Padding" Value="5" />
</Style>
</ResourceDictionary>
</Application.Resources>
設定它會自動將樣式應用到應用程式中的所有框架和標簽。
參考:https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/implicit
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/445078.html
標籤:C# 。网 xamarin xamarin.forms 毛伊岛
下一篇:foreach不能對“object”型別的變數進行操作,因為“object”不包含“GetEnumerator”的公共實體或擴展定義
