Skip to content

Latest commit

 

History

History
579 lines (502 loc) · 32.8 KB

Upgrading-Prism.md

File metadata and controls

579 lines (502 loc) · 32.8 KB

Upgrading Prism.Avalonia

This file documents the upgrade path of the Prism releases, noting files removed ❌ , added 🆕, and notes on breaking changes.

Icon Text Description
🔳 :white_square_button: Underway
✔️ :heavy_check_mark: Updated
🆕 :new: New
:x: Removed
⚠️ :warning: Pending
💔 :broken_heart: Never implemented in this platform

Overview Prism 8.1.97 to 9.0.x

This file documents the upgrade path from Prism v8.1.97 to v9.0-pre support. Soon we will be moving this repo to be apart of the main Prism Library :)

Each of the following will be tagged and merged into the branch Prism-9x before being merged with develop and master branches.

Release Comparison

As we all know, not everything is straight forward between these two XAML technologies. However, it's a good reminder to document the differences and 'got-yas'.

Changes

  • Samples folder renamed to e2e
  • Prism.Dialogs
    • Various updates, see section before for more info
  • NavigationResult returns the property Success instead of Result

Dialogs

Breaking Changes:

  • UPGRADE SAMPLE NEEDED
  • Namespace changed from Prism.Services.Dialogs to Prism.Dialogs.
  • IDialogAware property, RequestClose
    • Refactored from event to property (event Action<IDialogResult> RequestClose; -> DialogCloseListener RequestClose { get; })
    • Property is now read-only
  • IDialogService moved to Prism.Core
    • Deprecated void Show(...)
    • Deprecated void ShowDialog(Window owner, ...

Removed Files:

File Status Notes
ButtonResult.cs Absorbed into Prism.Core
DialogParameters.cs Absorbed into Prism.Core
DialogResult.cs Absorbed into Prism.Core
IDialogParameters.cs Absorbed into Prism.Core
IDialogResult.cs Absorbed into Prism.Core
IDialogService.cs 🔳 ❌ Absorbed into Prism.Core
IDialogServiceExtensions.cs Absorbed into Prism.Core
IDialogServiceCompatExtensions 🆕
KnownDialogParameters 🆕

Not Implemented:

  • IDialogWindow.Style - Custom window styles are not implemented at this time.
  • DialogWindow.axaml.cs - Does not implement this.AttachDevTools(); at this time - would be helpful during debugging

Avalonia vs WPF:

Avalonia WPF Reference
dialogWindow.Opened dialogWindow.Loaded
EventHandler<WindowClosingEventArgs>? Closing; event CancelEventHandler Closing; IDialogWindow.cs

Prism.DryIoc.Avalonia

File Status Notes
DryIocContainerExtension.cs New Prism.Container Packages

Prism.Avalonia.Tests

File Status Notes
MockHostAwareRegionBehavior.cs ✔️
MockPresentationRegion.cs ✔️
MockRegion.cs ✔️
MockRegionAdapter.cs ✔️
MockRegionBehavior.cs ✔️
MockRegionBehaviorCollection.cs ✔️
MockRegionManager.cs ✔️
MockRegionmanagerAccessor.cs ✔️
MockSortableViews.cs ✔️
MockViewsCollection.cs ✔️
PrismApplicationBaseFixture.cs ✔️
PrismBootstrapperBaseFixture.cs ✔️
AutoPopulateRegionBehaviorFixture.cs ✔️
RegionActiveAwareBehaviorFixture.cs ✔️
RegionManagerRegistrationBehaviorFixture.cs ✔️
RegionMemberlifetimeBehaviorFixture.cs ✔️
ContentControlRegionAdapterFixture.cs ✔️
RegionAdapterBaseFixture.cs ✔️
RegionBehaviorFixture.cs ✔️
RegionFixture.cs ✔️
RegionManagerRequestNavigateFixture.cs ✔️
RegionViewRegistryFixture.cs ✔️

Future Feature Work To Add

Project Class
Prism.Avalonia Interactivity/InvokeCommandAction
Prism.Avalonia.Tests Regions/ItemsControlRegionAdapterFixture
Prism.Avalonia.Tests Regions/SelectorRegionAdapterFixture

Upgrading from Prism 7.2 to 8.1

Action Items

  • Upgrade Prism.Avalonia
  • Upgrade Prism.DryIoc
  • Upgrade Prism.Unity
  • Remove IOCs not supported by Prism v8.1
  • Add Unit Tests, matching PrismLibrary
  • Upgrade Samples
  • Upgrade to .NET 6

Out of Scope

  • Add Prism Dialogs for Avalonia
  • Restructure folders to match PrismLibrary

Upgrade Progress

File Status Notes
Readme.md ⚠️ Needs updated to match 8.1.x NuGet package version
src\Readme.md 🆕 Added from PrismLibrary v8.1.x

Prism.Avalonia

File Status Notes
Prism.Avalonia.csproj ✔️ Added netcore and net45 targeting conditions, as per PrismLibrary v8.1.x
PrismApplicationBase.cs ✔️
Bootstrapper.cs ✔️ ❌ Renamed to PrismBootstrapperBase.cs
PrismBootstrapperBase.cs ✔️ 🆕 Replaces Boostrapper.cs
PrismInitializationExtensions.cs ✔️ ⚠️ 🆕 Needs, SelectorRegionAdapter.cs. Register container, Behavior, and Adapter goodies.
Common\MvvmHelpers.cs ✔️
Common\ObservableObject.cs ✔️ Needs verified
Common\UriParsingHelper.cs ✔️
Events\WeakDelegatesManager.cs ✔️ ❌ It's apart of Prism.Events
Extensions\CollectionExtensions.cs ✔️
Extensions\DependencyObjectExtensions.cs ⚠️ Needs verified. Rename to AvaloniaObjectionExtension?
Extensions\ExceptionExtension.cs ✔️ ❌
Extensions\ServiceLocationExtension.cs ✔️ ❌
Interactivity\CommandBehaviorBase.cs ✔️ ⚠️ Needs verification
Interactivity\InvokeCommandAction.cs ⚠️ 🆕 Needs converted to Avalonia; reference AvaloniaBehaviors.
Ioc\ContainerProviderExtension.cs ✔️ 🆕 ⚠️ Needs verification
Ioc\IContainerRegistryExtensions.cs ✔️
Logging\TextLogger.cs ✔️ ❌ Removed from Prism
Logging\TraceLogger.cs ✔️ ❌ Removed from Prism
Modularity\AssemblyResolver.Desktop.cs ✔️
Modularity\ConfigurationModuleCatalog.Desktop.cs ✔️
Modularity\ConfigurationStore.Desktop.cs ✔️
Modularity\DirectoryModuleCatalog.Desktop.cs ✔️ ❌
Modularity\DirectoryModuleCatalog.net45.cs ✔️ 🆕
Modularity\DirectoryModuleCatalog.netcore.cs ✔️ 🆕
Modularity\FileModuleTypeLoader.Desktop.cs ✔️
Modularity\IAssemblyResolver.Desktop.cs ✔️
Modularity\IConfigurationStore.Desktop.cs ✔️
Modularity\IModuleCatalogExtensions.cs ✔️
Modularity\IModuleGroupsCatalog.cs ✔️
Modularity\IModuleTypeLoader.cs ✔️
Modularity\ModuleAttribute.Desktop.cs ✔️
Modularity\ModuleCatalog.cs ✔️
Modularity\ModuleConfigurationElement.Desktop.cs ✔️
Modularity\ModuleConfigurationElementCollection.Desktop.cs ✔️
Modularity\ModuleDependencyCollection.Desktop.cs ✔️
Modularity\ModuleDependencyConfigurationElement.Desktop.cs ✔️
Modularity\ModuleDownloadProgressChangedEventArgs.cs ✔️ ❌
Modularity\ModuleInfo.cs ✔️
Modularity\ModuleInfo.Desktop.cs ✔️
Modularity\ModuleInfoGroup.cs ✔️
Modularity\ModuleInfoGroupExtensions.cs ✔️
Modularity\ModuleInitializer.cs ✔️
Modularity\ModuleManager.cs ✔️
Modularity\ModuleManager.Desktop.cs ✔️
Modularity\ModulesConfigurationSection.Desktop.cs ✔️
Modularity\ModuleTypeLoaderNotFoundException.cs ✔️
Modularity\ModuleTypeLoaderNotFoundException.Desktop.cs ✔️
Modularity\XamlModuleCatalog.cs 🔳 🆕 disabled; only used by WPF, not XF, Maui or UNO.
Mvvm\ViewModuleLocator.cs ✔️
Properties\AssemblyInfo ✔️
Properties\Resources.resx ✔️
Properties\Resources.Designer.cs ✔️
Properties\Settings.Designer.cs ✔️
Properties\Settings.settings ✔️
Regions\Behaviors\AutoPopulateRegionBehavior.cs ✔️
Regions\Behaviors\BindRegionContextToAvaloniaObjectBehavior.cs ✔️ Equivilant, BindRegionContextToDependencyObjectBehavior
Regions\Behaviors\ClearChildViewsRegionBehavior.cs ✔️
Regions\Behaviors\DelayedRegionCreationBehavior.cs ✔️ ⚠️ Needs Avalonia equivilant of FrameworkContentElement += Loaded
Regions\Behaviors\DestructibleRegionBehavior.cs ✔️ 🆕
Regions\Behaviors\IHostAwareRegionBehavior.cs ✔️
Regions\Behaviors\RegionActiveAwareBehavior.cs ✔️
Regions\Behaviors\RegionCreationException.cs ✔️
Regions\Behaviors\RegionCreationException.Desktop.cs ✔️
Regions\Behaviors\RegionManagerRegistrationBehavior.cs ✔️
Regions\Behaviors\RegionMemberLifetimeBehavior.cs ✔️
Regions\Behaviors\SelectorItemsSourceSyncBehavior.cs 🔳 ⚠️ Needs attention
Regions\Behaviors\SyncRegionContextWithHostBehavior.cs ✔️
Regions\AllActiveRegion.cs ✔️
Regions\ContentControlRegionAdapter.cs ✔️
Regions\DefaultRegionManagerAccessor.cs ✔️
Regions\IConfirmNavigationRequest.cs ✔️
Regions\IJournalAware.cs ✔️
Regions\INavigateAsync.cs ✔️
Regions\INavigationAware.cs ✔️
Regions\IRegion.cs ✔️
Regions\IRegionAdapter.cs ✔️
Regions\IRegionBehavior.cs ✔️
Regions\IRegionBehaviorCollection.cs ✔️
Regions\IRegionBehaviorFactory.cs ✔️
Regions\IRegionBehaviorFactoryExtensions.cs ✔️ 🆕
Regions\IRegionCollection.cs ✔️
Regions\IRegionManager.cs ✔️
Regions\IRegionManagerAccessor.cs ✔️
Regions\IRegionManagerExtensions.cs ✔️ 🆕
Regions\IRegionMemberLifetime.cs ✔️
Regions\IRegionNavigationContentLoader.cs ✔️
Regions\IRegionNavigationJournal.cs ✔️
Regions\IRegionNavigationJournalEntry.cs ✔️
Regions\IRegionNavigationService.cs ✔️
Regions\IRegionViewRegistry.cs ✔️
Regions\IViewsCollection.cs ✔️
Regions\ItemMetadata.cs ✔️
Regions\ItemsControlRegionAdapter.cs ✔️
Regions\NavigationAsyncExtensions.cs ✔️
Regions\NavigationContext.cs ✔️
Regions\NavigationParameters.cs ✔️
Regions\NavigationResult.cs ✔️
Regions\Region.cs ✔️
Regions\RegionAdapterBase.cs ✔️
Regions\RegionAdapterMappings.cs ✔️
Regions\RegionBehavior.cs ✔️
Regions\RegionBehaviorCollection.cs ✔️
Regions\RegionBehaviorFactory.cs ✔️
Regions\RegionContext.cs ✔️
Regions\RegionManager.cs ✔️
Regions\RegionMemberLifetimeAttribute.cs ✔️
Regions\RegionNavigationContentLoader.cs ✔️
Regions\RegionNavigationEventArgs.cs ✔️
Regions\RegionNavigationFailedEventArgs.cs ✔️
Regions\RegionNavigationJournal.cs ✔️
Regions\RegionNavigationJournalEntry.cs ✔️
Regions\RegionNavigationService.cs ✔️
Regions\RegionViewRegistry.cs ✔️
Regions\SelectorRegionAdapter.cs 🔳 ⚠️ Needs attention - Commented out and disabled in PrismInitializationExtensions
Regions\SingleActiveRegion.cs ✔️
Regions\SyncActiveStateAttribute.cs ✔️
Regions\UpdateRegionsException.Desktop.cs ✔️
Regions\UpdateRegionsException.cs ✔️
Regions\ViewRegisteredEventArgs.cs ✔️
Regions\ViewRegistrationException.Desktop.cs ✔️
Regions\ViewRegistrationException.cs ✔️
Regions\ViewSortHintAttribute.cs ✔️
Regions\ViewsCollection.cs ✔️
Services\Dialogs\ButtonResult.cs 🆕 ✔️
Services\Dialogs\Dialog.cs 🆕 ✔️
Services\Dialogs\DialogParameters.cs 🆕 ✔️
Services\Dialogs\DialogResult.cs 🆕 ✔️
Services\Dialogs\DialogService.cs 🆕 ✔️
Services\Dialogs\DialogWindow.xaml 🆕 ✔️
Services\Dialogs\DialogWindow.xaml.cs 🆕 ✔️
Services\Dialogs\IDialogAware.cs 🆕 ✔️
Services\Dialogs\IDialogParameters.cs 🆕 ✔️
Services\Dialogs\IDialogResult.cs 🆕 ✔️
Services\Dialogs\IDialogService.cs 🆕 ✔️
Services\Dialogs\IDialogServiceExtensions.cs 🆕 ✔️
Services\Dialogs\IDialogWindow.cs 🆕 ✔️
Services\Dialogs\IDialogWindowExtensions.cs 🆕 ✔️

Containers

Containers is a 🆕 Folder

File Status Notes
Containers\Prism.DryIoc.Shared\DryIocContainerExtension.cs 🆕
Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems 🆕
Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj 🆕
Containers\Prism.DryIoc.Shared\PrismIocExtensions.cs 🆕
Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems 🆕
Containers\Prism.Unity.Shared\Prism.Unity.Shared.shproj 🆕
Containers\Prism.Unity.Shared\PrismIocExntensions.cs 🆕
Containers\Prism.Unity.Shared\UnityContainerExtension.cs 🆕

Prism.DryIoc.Avalonia

File Status Notes
Prism.DryIoc.Avalonia.csproj.cs ✔️ Updated to DryIoc v4.8.1
DryIocServiceLocatorAdapter.cs
GlobalSuppressions.cs ✔️
PrismApplication.cs ✔️
PrismBootstrapper.cs 🆕
Ioc\DryIocContainerExtension.cs Moved to Containers
Ioc\PrismIocExtensions.cs Moved to Containers
Legacy\DryIocBootstrapper.cs
Legacy\DryIocExtensions.cs
Properties\AssemblyInfo 🆕
Properties\Resources.Designer.resx 🔳
Properties\Resources.resx 🔳

Prism.Unity.Avalonia

File Status Notes
PrismApplication.cs ✔️
PrismBootstrapper.cs ✔️
GlobalSuppressions.cs ✔️

Tests - Prism.Avalonia.Tests

Test writted to Prism.WPF specs.

File Status Notes
Prism.Avalonia.Tests.csproj ✔️ Upgraded to .NET 6 (Prism v8.1.97 uses .NET v4.7.1)
CollectionChangedTracker.cs ✔️
CollectionExtensionsFixture.cs ✔️
CompilerHelper.Desktop.cs ✔️
ExceptionAssert.cs ✔️
ListDictionaryFixture.cs ✔️
CollectionChangedTracker.cs ✔️
PrismApplicationBaseFixture.cs ✔️ ⚠️
PrismBootstrapperBaseFixture.cs ✔️ Throwing, "protection level errors."
Logging\ ...
Interactivity\CommandBehaviorBaseFixture.cs ✔️
Interactivity\InvokeCommandActionFixture.cs ✔️
Mocks\Modules\MockAbstractModule.cs ✔️
Mocks\Modules\MockAttributedModule.cs ✔️
Mocks\Modules\MockDependantModule.cs ✔️
Mocks\Modules\MockDependencyModule.cs ✔️
Mocks\Modules\MockExposingTypeFromGacAssemblyModule.cs ✔️
Mocks\Modules\MockModuleA.cs ✔️
Mocks\Modules\MockModuleReferencedAssembly.cs ✔️
Mocks\Modules\MockModuleReferencingAssembly.cs ✔️
Mocks\Modules\MockModuleReferencingOtherModule.cs ✔️
Mocks\Modules\MockModuleThrowingException.cs ✔️
Mocks\MockAsyncModuleTypeLoader.cs ✔️
Mocks\MockClickableObject.cs ✔️
Mocks\MockCommand.cs ✔️
Mocks\MockConfigurationStore.Desktop.cs ✔️
Mocks\MockContainerAdapter.cs ✔️
Mocks\MockDelegateReference.cs ✔️
Mocks\MockDependencyObject.cs ✔️
Mocks\MockFrameworkContentElement.cs ✔️ ⚠️ [AvaloniaUI/Avalonia#8277]
Mocks\MockFrameworkElement.cs ✔️ ⚠️
Mocks\MockHostAwareRegionBehavior.cs ✔️
Mocks\MockPresentationRegion.cs ✔️
Mocks\MockRegion.cs ✔️
Mocks\MockRegionAdapter.cs ✔️
Mocks\MockRegionBehavior.cs ✔️
Mocks\MockRegionBehaviorCollection.cs ✔️
Mocks\MockRegionManager.cs ✔️
Mocks\MockRegionManagerAccessor.cs ✔️
Mocks\MockSortableViews.cs ✔️
Mocks\MockViewsCollection.cs ✔️
ViewModels\MockOptOutViewModel.cs ✔️
ViewModels\MockViewModel.cs ✔️
Views\Mock.cs ✔️
Views\MockOptOut.cs ✔️
Views\MockView.cs ✔️
Modularity\AssemblyResolverFixture.Desktop.cs ✔️
Modularity\ConfigurationModuleCatalogFixture.cs ✔️
Modularity\ConfigurationStoreFixture.cs ✔️
Modularity\DirectoryModuleCatalogFixture.cs 🔳 ⚠️
Modularity\FileModuleTypeLoaderFixture.Desktop.cs ✔️
Modularity\ModuleAttributeFixture.Desktop.cs ✔️
Modularity\ModuleCatalogFixture.cs ✔️
Modularity\ModuleDependencySolverFixture.cs ✔️
Modularity\ModuleInfoGroupExtensionsFixture.cs ✔️
Modularity\ModuleInfoGroupFixture.cs ✔️
Modularity\ModuleInitializerFixture.cs ✔️
Modularity\ModuleManagerExtensionsFixture.cs ✔️
Modularity\ModuleManagerFixture.cs ✔️
Modularity\XamlModuleCatalogFixture.txt.dll ✔️
Modularity\DirectoryModuleCatalogFixture.cs ✔️
Modularity\ModuleCatalogXml\InvalidDependencyModuleCatalog.xaml ✔️
Modularity\ModuleCatalogXml\SimpleModuleCatalog.xaml ✔️
Mvvm\ViewModelLocatorFixture.cs ✔️
Regions\AllActiveRegionFixture.cs ✔️
Regions\ContentControlRegionAdapterFixture.cs ✔️ ⚠️
Regions\ItemsControlRegionAdapterFixture.cs 🔳 ⚠️ [AvaloniaUI/Avalonia#7553]
Regions\LocatorNavigationTargetHandlerFixture.cs ✔️
Regions\NavigationAsyncExtensionsFixture.cs ✔️
Regions\NavigationContextFixture.cs ✔️
Regions\NavigationParametersFixture.cs ✔️
Regions\RegionAdapterBaseFixture.cs ✔️
Regions\RegionAdapterMappingsFixture.cs ✔️
Regions\RegionBehaviorCollectionFixture.cs ✔️
Regions\RegionBehaviorFactoryFixture.cs ✔️
Regions\RegionBehaviorFixture.cs ✔️
Regions\RegionFixture.cs ✔️
Regions\RegionManagerFixture.cs ✔️
Regions\RegionManagerRequestNavigateFixture.cs ✔️
Regions\RegionNavigationJournalFixture.cs ✔️
Regions\RegionNavigationServiceFixture.new.cs ✔️
Regions\RegionViewRegistryFixture.cs ✔️
Regions\SelectorRegionAdapterFixture.cs 🔳 🆕 ⚠️
Regions\SingleActiveRegionFixture.cs ✔️
Regions\ViewsCollectionFixture.cs ✔️
Regions\Behaviors\AutoPopulateRegionBehaviorFixture.cs ✔️
Regions\Behaviors\BindRegionContextToDependencyObjectBehaviorFixture.cs ✔️
Regions\Behaviors\ClearChildViewsRegionBehaviorFixture.cs ✔️
Regions\Behaviors\DelayedRegionCreationBehaviorFixture.cs ✔️
Regions\Behaviors\RegionActiveAwareBehaviorFixture.cs ✔️
Regions\Behaviors\RegionManagerRegistrationBehaviorFixture.cs ✔️
Regions\Behaviors\RegionMemberLifetimeBehaviorFixture.cs ✔️
Regions\Behaviors\SelectorItemsSourceSyncRegionBehaviorFixture.cs 🔳 ⚠️
Regions\Behaviors\SyncRegionContextWithHostBehaviorFixture.cs ✔️

Tests - Prism.Container.Avalonia.Shared

File Status Notes
Fixtures\ContainerExtensionCollection.cs ✔️
Mocks\NullModuleCatalogBootstrapper.cs ✔️

Tests - Prism.DryIoc.Avalonia.Tests

TBD

File Status Notes

Conversion Helpers

[https://docs.avaloniaui.net/misc/wpf/Control-frameworkelement-and-control]

WPF Avalonia Reference
System.Windows Avalonia
System.Windows.FrameworkElement Avalonia.Controls.Control Reference
System.WIndows.FrameworkContentElement Avalonia.Controls.Control
UIElement Avalonia.Controls.Control
ItemsControl.ItemsSource Avalonia.Controls.ItemsControl.ItemsSource Naming Convention
System.Windows.Markup.MarkupExtension Avalonia.Markup.Xaml.MarkupExtension Reference
System.Windows.Markup.ContentPropertyAttribute.ContentProperty Avalonia.Metadata.Content [AvaloniaUI/Avalonia#1126]
System.Windows.Markup Avalonia.Markup.Xaml
System.Windows.Markup.XmlnsDefinition Avalonia.Metadata.XmlnsDefinition
System.Windows.DependencyObject Avalonia.AvaloniaObject
System.Windows.DependencyProperty Avalonia.AvaloniaProperty
System.Windows.DependencyPropertyChangedEventArgs Avalonia.AvaloniaPropertyChangedEventArgs
System.ComponentModel.DesignerProperties.GetIsInDesignMode(DependencyObject element); Avalonia.Controls.Design.IsDesignMode;
System.Windows.Controls.Primitives.Selector ?? used by SelectorRegionAdapter.cs and PrismInitializationExtensions.cs
RoutedEventHandler EventHandler

AvaloniaProperty vs DependencyProperty

Note, Avalonia places the propertyType as part of TValue in its ..<THost, TValue>(...).

// Avalonia
public static AvaloniaProperty AutoWireViewModelProperty =
    AvaloniaProperty.RegisterAttached<Control, bool>(
        name: "AutoWireViewModel",
        ownerType: typeof(ViewModelLocator),
        defaultValue: false);

// WPF
public static DependencyProperty AutoWireViewModelProperty =
    DependencyProperty.RegisterAttached(
        name: "AutoWireViewModel",
        propertyType: typeof(bool?),
        ownerType: typeof(ViewModelLocator),
        defaultMetaData: new PropertyMetadata(defaultValue: null, propertyChangedCallback: AutoWireViewModelChanged));

Behaviors and Triggers

In order to use Behaviors in Avalonia, you must download the Avalonia XAML Behaviors NuGet.

For example, InvokeCommandActionView.axaml uses InvokeCommandAction.cs.

Inheriting WPF DependencyObject in Avalonia

// WPF:
public partial class ItemMetadata : DependencyObject
{
    ...
    private static void DependencyPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
    {
        ItemMetadata itemMetadata = dependencyObject as ItemMetadata;
        if (itemMetadata != null)
        {
            itemMetadata.InvokeMetadataChanged();
        }
    }

// Avalonia:
public class ItemMetadata : AvaloniaObject
{
    ...
    private static void StyledPropertyChanged(IAvaloniaObject dependencyObject, AvaloniaPropertyChangedEventArgs args)
    {
        ItemMetadata itemMetadata = dependencyObject as ItemMetadata;
        if (itemMetadata != null)
        {
            itemMetadata.InvokeMetadataChanged();
        }
    }

Property

Note:

  • Avalonia places WPF's propertyType as part of TValue in <THost, TValue>
  • The THost object type is what is used in the Get and Set methods.
// Avalonia ------------
private static readonly AvaloniaProperty ObservableRegionContextProperty =
    AvaloniaProperty.RegisterAttached<Visual, ObservableObject<object>>(
        name: "ObservableRegionContext",
        ownerType: typeof(RegionContext));

static RegionContext()
{
    ObservableRegionContextProperty.Changed.Subscribe(args => GetObservableContext(args?.Sender as Visual));
}

// WPF -----------------
private static readonly DependencyProperty ObservableRegionContextProperty =
    DependencyProperty.RegisterAttached(
        name: "ObservableRegionContext",
        propertyType: typeof(ObservableObject<object>),
        ownerType: typeof(RegionContext),
        defaultMetadata: null);

Property with Callback

Make sure to include, using System; or else .Subscribe(..) will throw an error.

using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Styling;

// Avalonia ------------------
static ClassConstructor()
{
    RegionNameProperty.Changed.Subscribe(args => OnSetRegionNameCallback(args?.Sender, args));
}

public static readonly AvaloniaProperty RegionNameProperty = AvaloniaProperty.RegisterAttached<AvaloniaObject, string>(
    name: "RegionName",
    ownerType: typeof(RegionManager));

// WPF -----------------------
public static readonly DependencyProperty RegionNameProperty = DependencyProperty.RegisterAttached(
    name: "RegionName",
    propertyType: typeof(string),
    ownerType: typeof(RegionManager),
    defaultMetadata: new PropertyMetadata(defaultValue: null, propertyChangedCallback: OnSetRegionNameCallback));