Open robloo opened 1 year ago
@maxkatz6 @grokys @kekekeks @danwalmsley Just FYI as it might be good to read through this before 11.0. Still a work-in-process but this list is made from looking at WinUI code in prep for a port.
The showstoppers for app migration WinUI -> Avalonia and most pain points (like CornerRadius, etc.) have been fixed. Only smaller things and differences are above.
I've started to do a more detailed look at porting a UWP/WinUI app over to Avalonia and think a detailed guide would be useful (several apply to WPF as well). Below I'll collect the things I've found so far in the hopes of adding a dedicated page to the docs eventually.
XAML
xmlns="https://github.com/avaloniaui
x:CompileBindings="True"
where possible (it is supported in most cases now)ThemeResource
usages withDynamicResource
<ResourceDictionary.ThemeDictionaries>
Light/Dark/HighContrast dictionaries. Avalonia does not conceptually support this yet and will use a different pattern when this functionality is added. For now, resource dictionaries for dark/light should be manually loaded.UpdateSourceTrigger
usage which was common in WPF/WinUI TextBoxes. See https://github.com/AvaloniaUI/Avalonia/issues/3754Grid
andStackPanel
Style
property usage. This usually requires switching to theTheme
property with a newControlTheme
or use style classes.BorderBrush
,Background
andBorderThickness
property usage fromGrid
. Place theGrid
inside aBorder
which has these properties like what was done in WPF. UWP/WinUI did this to flatten the visual tree for performance but it never made a lot of sense as Grid was just layout and should have no visual style.ComboBox.SelectionChangedTrigger="Committed"
which isn't supported in AvaloniaDisplayMemberPath
,SelectedValue
andSelectedValuePath
: https://github.com/AvaloniaUI/Avalonia/issues/4718. This requires some changes to view models to work-around and possibly switching types. More recentlyDisplayMemberBinding
was added to replaceDisplayMemberPath
: https://github.com/AvaloniaUI/Avalonia/pull/8922Visibility
toIsVisible
. This is one of the more involved changes and requires not only renames and property setter updates, but also converter and view model changes.Style
toControlTheme
in the cases of default control template stylesStyle
to using selectors and classes when not changing control templatesSplitButton
,ToggleSplitButton
,DropDownButton
,ColorPicker
etc. out of the box.ContentDialog
, etc.) It is best to use FluentAvalonia to add back most of the missing controls when porting from UWP/WinUIFontIcon
-> Fluent Avalonia'sFontIcon
ListView
->ListBox
DataTemplateSelector
pattern https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/DataTemplates/IDataTemplateSampleAcrylicBrush
usage must be removed. Avalonia currently supports an experimental acrylic material but it is usable only onBorder.Material
property so is conceptually different. Note that the entire window can still simulate acrylic/mica using different methodologyTransparencyLevelHint="AcrylicBlur"
.x:Uid='key'
resource localization. For localized apps, this creates another very involved change. The recommended approach is to create a localization/translation markup extension and consume .resx files by the extension. See: https://github.com/AvaloniaUI/Avalonia/discussions/8741#discussioncomment-4009674IGrouping
cannot be used norCollectionViewSource
orListView.GroupStyle
. To work-around this custom ListBoxItems must be created with different data templates.Code-Behind
.ActualHeight
and.ActualWidth
must be changed to.Bounds.Height
and.Bounds.Width
UIElement
toobject?
orIControl?
for content propertiesFrameworkElement
toControl
Brush
Background/BorderBrush toIBrush?
(Brush)Application.Current.Resources["key"];
generally doesn't work as it won't search the full resources (https://github.com/AvaloniaUI/Avalonia/issues/6021). An extension method as described in the issue is generally the easiest fix but this still requires changing all usages in code.Other
Visibility
->IsVisible
. This shows up everywhere.Note: I might complete a base version of this for my own public docs repository. We'll see. Just collecting things here for now.