此 iOS 平臺特定設定實例的預設背景色彩 Cell 。 將可繫結屬性設定 Cell.DefaultBackgroundColor 為 Color,以在 XAML 中取用它:
<ContentPage ...
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
<StackLayout Margin="20">
<ListView ItemsSource="{Binding GroupedEmployees}"
IsGroupingEnabled="true">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell ios:Cell.DefaultBackgroundColor="Teal">
<Label Margin="10,10"
Text="{Binding Key}"
FontAttributes="Bold" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
...
</ListView>
</StackLayout>
</ContentPage>
或者,您可以使用 Fluent API 從 C# 取用它:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...
var viewCell = new ViewCell { View = ... };
viewCell.On<iOS>().SetDefaultBackgroundColor(Color.Teal);
方法 ListView.On<iOS> 會指定此平台專屬只會在iOS上執行。 在命名空間中,方法Cell.SetDefaultBackgroundColor會將儲存格背景色彩設定為指定的 Color。Xamarin.Forms.PlatformConfiguration.iOSSpecific 此外, Cell.DefaultBackgroundColor 方法可以用來擷取目前的儲存格背景色彩。
結果是 中的 Cell 背景色彩可以設定為特定的 Color:
