Platform-Specifics

Download Sample Download the sample

Platform-specifics allow you to consume functionality that's only available on a specific platform, without implementing custom renderers or effects.

The following platform-specific functionality is provided for Xamarin.Forms views, pages, and layouts:

iOS Android Windows
VisualElement.BlurEffect VisualElement.Elevation VisualElement.AccessKey, VisualElement.AccessKeyPlacement, VisualElement.AccessKeyHorizontalOffset, and VisualElement.AccessKeyVerticalOffset
VisualElement.IsLegacyColorModeEnabled VisualElement.IsLegacyColorModeEnabled VisualElement.IsLegacyColorModeEnabled
VisualElement.IsShadowEnabled

The following platform-specific functionality is provided for Xamarin.Forms views:

iOS Android Windows
Entry.AdjustsFontSizeToFitWidth Button.UseDefaultPadding and Button.UseDefaultShadow InputView.DetectReadingOrderFromContent, Label.DetectReadingOrderFromContent
Entry.CursorColor Entry.ImeOptions ListView.SelectionMode
ListView.SeparatorStyle ImageButton.IsShadowEnabled SearchBar.IsSpellCheckEnabled
Picker.UpdateMode ListView.IsFastScrollEnabled WebView.IsJavaScriptAlertEnabled
Slider.UpdateOnTap WebView.MixedContentMode

The following platform-specific functionality is provided for Xamarin.Forms pages:

iOS Android Windows
NavigationPage.HideSeparatorBar NavigationPage.BarHeight MasterDetailPage.CollapsedPaneWidth and MasterDetailPage.CollapseStyle
NavigationPage.IsNavigationBarTranslucent TabbedPage.IsSmoothScrollEnabled Page.ToolbarPlacement
NavigationPage.StatusBarTextColorMode TabbedPage.IsSwipePagingEnabled TabbedPage.HeaderIconsEnabled and TabbedPage.HeaderIconsSize
NavigationPage.PrefersLargeTitles TabbedPage.ToolbarPlacement, TabbedPage.BarItemColor, and TabbedPage.BarSelectedItemColor
Page.ModalPresentationStyle
Page.PrefersStatusBarHidden and Page.PreferredStatusBarUpdateAnimation
Page.UseSafeArea

The following platform-specific functionality is provided for Xamarin.Forms layouts:

iOS
ScrollView.ShouldDelayContentTouches

The following platform-specific functionality is provided for the Xamarin.Forms Application class:

iOS Android
Application.HandleControlUpdatesOnMainThread Application.WindowSoftInputModeAdjust
Application.PanGestureRecognizerShouldRecognizeSimultaneously Application.SendDisappearingEventOnPause, Application.SendAppearingEventOnResume, and Application.ShouldPreserveKeyboardOnResume

Consuming platform-specifics

The process for consuming a platform-specific through XAML, or through the fluent code API is as follows:

  1. Add a xmlns declaration or using directive for the Xamarin.Forms.PlatformConfiguration namespace.
  2. Add a xmlns declaration or using directive for the namespace that contains the platform-specific functionality:
    1. On iOS, this is the Xamarin.Forms.PlatformConfiguration.iOSSpecific namespace.
    2. On Android, this is the Xamarin.Forms.PlatformConfiguration.AndroidSpecific namespace. For Android AppCompat, this is the Xamarin.Forms.PlatformConfiguration.AndroidSpecific.AppCompat namespace.
    3. On the Universal Windows Platform, this is the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace.
  3. Apply the platform-specific from XAML, or from code with the On<T> fluent API. The value of T can be the iOS, Android, or Windows types from the Xamarin.Forms.PlatformConfiguration namespace.

Note

Note that attempting to consume a platform-specific on a platform where it is unavailable will not result in an error. Instead, the code will execute without the platform-specific being applied.

Platform-specifics consumed through the On<T> fluent code API return IPlatformElementConfiguration objects. This allows multiple platform-specifics to be invoked on the same object with method cascading.

For more information about platform-specifics, see Consuming Platform-Specifics and Creating Platform-Specifics.