次の方法で共有


iOS でのセルの背景色

この .NET Multi-platform App UI (.NET MAUI) iOS プラットフォーム固有設定で、Cell インスタンスの既定の背景色を設定します。 Cell.DefaultBackgroundColor バインド可能なプロパティを Color に設定することによって XAML で使用されます。

<ContentPage ...
             xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls">
    <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 Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...

ViewCell viewCell = new ViewCell { View = ... };
viewCell.On<iOS>().SetDefaultBackgroundColor(Colors.Teal);

ListView.On<iOS> メソッドは、このプラットフォーム固有設定が iOS でのみ実行されるように指定します。 Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific 名前空間の Cell.SetDefaultBackgroundColor メソッドは、セルの背景色を指定した Color に設定します。 さらに、Cell.DefaultBackgroundColor メソッドを使用して、現在のセルの背景色を取得できます。

その結果、Cell の背景色を特定の Color に設定できます。

Screenshot of the Teal group header cells, on iOS.