共用方式為


iOS 上的 VisualElement 舊版色彩模式

某些 Xamarin.Forms 檢視具有舊版色彩模式。 在此模式中,當檢視的屬性設定為 falseIsEnabled,檢視會覆寫使用者為停用狀態的預設原生色彩所設定的色彩。 為了回溯相容性,此舊版色彩模式會維持支持檢視的默認行為。

此 iOS 平臺特定會停用 上的 VisualElement這個舊版色彩模式,讓使用者在檢視上設定的色彩即使在停用檢視時仍維持不變。 將附加屬性false設定VisualElement.IsLegacyColorModeEnabled為 ,以在 XAML 中取用它:

<ContentPage ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout>
        ...
        <Button Text="Button"
                TextColor="Blue"
                BackgroundColor="Bisque"
                ios:VisualElement.IsLegacyColorModeEnabled="False" />
        ...
    </StackLayout>
</ContentPage>

或者,您可以使用 Fluent API 從 C# 取用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

_legacyColorModeDisabledButton.On<iOS>().SetIsLegacyColorModeEnabled(false);

方法 VisualElement.On<iOS> 會指定此平台專屬只會在iOS上執行。 命名空間 VisualElement.SetIsLegacyColorModeEnabled 中的 Xamarin.Forms.PlatformConfiguration.iOSSpecific 方法可用來控制是否停用舊版色彩模式。 此外, VisualElement.GetIsLegacyColorModeEnabled 方法可用來傳回是否停用舊版色彩模式。

結果是可以停用舊版色彩模式,讓使用者在檢視上設定的色彩即使在停用檢視時仍會保留:

已停用舊版色彩模式

注意

在檢視上設定 VisualStateGroup 時,會完全忽略舊版色彩模式。 如需視覺狀態的詳細資訊,請參閱 Xamarin.Forms Visual State Manager