Back to Uno

Control Mappings from Xamarin.Forms to Uno Platform

doc/articles/guides/xf-migration/control-mappings.md

6.6-release-branch-cut9.8 KB
Original Source

Control Mappings from Xamarin.Forms to Uno Platform

This guide provides a comprehensive mapping of Xamarin.Forms controls and their equivalents in Uno Platform/WinUI. Understanding these mappings is essential when migrating your Xamarin.Forms application to Uno Platform.

Layout Controls

Xamarin.FormsUno Platform / WinUINotes
StackLayoutStackPanelSet Orientation property for horizontal/vertical layout
GridGridSame control name, similar API with RowDefinitions and ColumnDefinitions
AbsoluteLayoutCanvasUse Canvas.Left, Canvas.Top for positioning
RelativeLayoutRelativePanelDifferent API - uses attached properties for relationships
FlexLayoutCustom implementation or VariableSizedWrapGridNo direct equivalent; consider redesigning with Grid or StackPanel
ScrollViewScrollViewerSimilar functionality with additional properties
ContentViewContentControlBase class for custom controls
FrameBorderUse CornerRadius, BorderBrush, BorderThickness

Text Controls

Xamarin.FormsUno Platform / WinUINotes
LabelTextBlockFor read-only text display
EntryTextBoxSingle-line text input
EditorTextBox with AcceptsReturn="True"Multi-line text input
SearchBarAutoSuggestBoxProvides search functionality with suggestions
Span (in FormattedString)Run (in TextBlock)For inline formatted text

Button and Input Controls

Xamarin.FormsUno Platform / WinUINotes
ButtonButtonSame control name
ImageButtonButton with Image contentOr use AppBarButton with icon
CheckBoxCheckBoxSame control name
SwitchToggleSwitchDifferent control with on/off states
SliderSliderSame control name
StepperNumberBoxProvides increment/decrement functionality
DatePickerDatePicker or CalendarDatePickerChoose based on UI requirements
TimePickerTimePickerSame control name
PickerComboBoxDropdown selection control
RadioButtonRadioButtonAvailable in WinUI 2.5+

Collection Controls

Xamarin.FormsUno Platform / WinUINotes
ListViewListViewSame control name with different templating
CollectionViewItemsRepeater or ListViewItemsRepeater for flexible layouts
CarouselViewFlipViewSwipeable item view
TableViewCustom with ListView or ItemsRepeaterNo direct equivalent
RefreshViewRefreshContainerPull-to-refresh functionality
SwipeViewCustom implementationUse SwipeControl on supported platforms
IndicatorViewCustom implementationCreate with ItemsRepeater or dots pattern

Visual and Media Controls

Xamarin.FormsUno Platform / WinUINotes
ImageImageSame control name
ImageButtonButton with ImageOr use icon fonts
BoxViewRectangle or BorderFor colored rectangles
WebViewWebView2Requires WebView2 runtime on Windows
MediaElementMediaPlayerElementFor audio/video playback
MapThird-party map controlsUse Uno.Extensions or platform-specific maps
ActivityIndicatorProgressRingIndeterminate progress indicator
ProgressBarProgressBarSame control name

Page and Navigation

Xamarin.FormsUno Platform / WinUINotes
ContentPagePageBase page type
NavigationPageFrame with navigationSee Migrating Navigation
TabbedPageNavigationView or TabViewBottom tabs or top tabs
CarouselPageFlipViewSwipeable pages
MasterDetailPageNavigationViewSplit view with menu
ShellNavigationView with routingSee navigation guide
FlyoutPageNavigationViewReplaces MasterDetailPage

Special Controls

Xamarin.FormsUno Platform / WinUINotes
ToolbarItemAppBarButton in CommandBarTop app bar buttons
MenuItemMenuFlyoutItemContext menu items
ContextActionsMenuFlyout or SwipeBehaviorRight-click or swipe actions
Shapes (Rectangle, Ellipse, etc.)Windows.UI.Xaml.Shapes namespaceSame shape controls

Property Mappings

Size and Layout

Xamarin.FormsUno Platform / WinUI
HeightRequestHeight
WidthRequestWidth
MinimumHeightRequestMinHeight
MinimumWidthRequestMinWidth
HorizontalOptionsHorizontalAlignment
VerticalOptionsVerticalAlignment
MarginMargin (same)
PaddingPadding (same)

Alignment Values

Xamarin.FormsUno Platform / WinUI
StartLeft
EndRight
CenterCenter
FillStretch

Colors and Styling

Xamarin.FormsUno Platform / WinUI
BackgroundColorBackground (use SolidColorBrush)
TextColorForeground (use SolidColorBrush)
BorderColorBorderBrush (use SolidColorBrush)
Color.Accent{ThemeResource SystemAccentColor}
Color.DefaultTheme-dependent resources

Text and Fonts

Xamarin.FormsUno Platform / WinUI
FontSizeFontSize (same)
FontAttributes="Bold"FontWeight="Bold"
FontAttributes="Italic"FontStyle="Italic"
FontFamilyFontFamily (same)
TextTransformCustom converter or CharacterCasing

Behaviors and Attachments

Xamarin.FormsUno Platform / WinUINotes
Behavior<T>Attached properties or Microsoft.Xaml.BehaviorsUse Uno.Toolkit or create custom attached properties
TriggerActionVisual states or code-behindSee Effects guide
DataTriggerVisual states with StateTriggerUse AdaptiveTrigger, StateTrigger
EventTriggerEvent handlers or behaviorsUse code-behind or behaviors library

Services and Dependency Injection

Xamarin.FormsUno Platform / WinUINotes
DependencyServiceBuilt-in DI (IServiceProvider)Use constructor injection with IHost
MessagingCenterEvent aggregator or messenger patternUse Uno.Extensions messaging or CommunityToolkit.Mvvm Messenger

Application Lifecycle

Xamarin.FormsUno Platform / WinUINotes
Application.OnStartApp.OnLaunchedApplication startup
Application.OnSleepApplication.EnteredBackgroundApp backgrounded
Application.OnResumeApplication.LeavingBackgroundApp foregrounded
Application.MainPageWindow.Content or navigation setupSet root content

No Direct Equivalent

Some Xamarin.Forms features don't have direct equivalents and require alternative approaches:

CollectionView Features

  • EmptyView: Implement with conditional visibility and custom empty state UI
  • ItemsLayout: Use ItemsPanel with different panel templates in ListView or ItemsRepeater
  • RemainingItemsThreshold: Implement using IncrementalLoadingTrigger or scroll position monitoring

SwipeView

  • Use platform-specific implementations with conditional compilation
  • Consider SwipeControl for Windows 10+
  • Implement custom gestures for other platforms

Shell Navigation

  • Use Uno.Extensions.Navigation for similar URI-based routing
  • Implement with Frame and view models for simpler scenarios
  • Use NavigationView for hierarchical navigation

FlexLayout

  • Redesign layouts using Grid with responsive triggers
  • Use VariableSizedWrapGrid for simple wrapping scenarios
  • Consider CSS Grid on WebAssembly with HTML embedding

Migration Strategy

When migrating controls:

  1. Identify usage patterns: Search for all instances of a Xamarin.Forms control
  2. Map to equivalent: Use the tables above to find the Uno Platform equivalent
  3. Update properties: Map property names according to the property mappings
  4. Test on target platforms: Verify behavior on all platforms you're targeting
  5. Refactor if needed: Some controls may require redesign for better Uno Platform patterns

Platform-Specific Considerations

Native Renderer vs Skia

  • Native renderer on iOS/Android: Maps WinUI controls to native platform controls
  • Skia renderer: Uses Skia for consistent pixel-perfect rendering across platforms
  • Some controls behave differently between renderers - test thoroughly

WebAssembly

  • WebView2 becomes an HTML iframe
  • Media controls may have limitations
  • File pickers use browser file input

Performance

  • ListView and ItemsRepeater are optimized for large lists
  • Use virtualization for long scrolling lists
  • Consider ItemsStackPanel or ItemsWrapGrid for layout panels

Next Steps

See Also