VisualElement Legacy Color Mode on iOS
Some of the Xamarin.Forms views feature a legacy color mode. In this mode, when the IsEnabled
property of the view is set to false
, the view will override the colors set by the user with the default native colors for the disabled state. For backwards compatibility, this legacy color mode remains the default behavior for supported views.
This iOS platform-specific disables this legacy color mode on a VisualElement
, so that colors set on a view by the user remain even when the view is disabled. It's consumed in XAML by setting the VisualElement.IsLegacyColorModeEnabled
attached property to false
:
<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>
Alternatively, it can be consumed from C# using the fluent API:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...
_legacyColorModeDisabledButton.On<iOS>().SetIsLegacyColorModeEnabled(false);
The VisualElement.On<iOS>
method specifies that this platform-specific will only run on iOS. The VisualElement.SetIsLegacyColorModeEnabled
method, in the Xamarin.Forms.PlatformConfiguration.iOSSpecific
namespace, is used to control whether the legacy color mode is disabled. In addition, the VisualElement.GetIsLegacyColorModeEnabled
method can be used to return whether the legacy color mode is disabled.
The result is that the legacy color mode can be disabled, so that colors set on a view by the user remain even when the view is disabled:
Note
When setting a VisualStateGroup
on a view, the legacy color mode is completely ignored. For more information about visual states, see The Xamarin.Forms Visual State Manager.