Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v11-Prev 5 - After Upgrading Prism Module Region Fails Inside of ItemsControl #47

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

DamianSuess
Copy link
Collaborator

@DamianSuess DamianSuess commented Feb 6, 2023

Issue

After upgrading to Avalonia v11-Preview5, Prism Modules can fail to register a region defined in XAML.

The error is being thrown in ItemsControlRegionAdapter.Adapt(IRegion region, ItemsControl regionTarget) when it attempts to set regionTarget.Items = region.Views;. Which is equivalent to Avalonia.Collections.AvaloniaList<object> = Prism.Regions.ViewsCollection. To address this, IViewsCollection may need to inherit IList (by why all a sudden?)

  <!-- DummyModuleView2.axaml -->
  <ItemsControl prismRegions:RegionManager.RegionName="ListRegion"></ItemsControl>

Reproduce

  1. Pull latest Develop branch
  2. Set sample app, ModuleSampleApp as Startup Project
  3. Run the code
  4. The above error will be thrown before the window renders

Research

Currently, I'm looking into what changed in the architecture to warrant this modification. This could be why the sample app, ViewDiscovery, is also failing to operate correctly

Error Message:

Prism.Regions.Behaviors.RegionCreationException: 'An exception occurred while creating a region with name 'ListRegion'. The exception was: System.ArgumentException: Collection implements INotifyCollectionChanged but not IList. (Parameter 'source')

Call Stack:

This exception was originally thrown at this call stack:
    Avalonia.Controls.ItemsSourceView.ItemsSourceView(System.Collections.IEnumerable) in ItemsSourceView.cs
    Avalonia.Controls.ItemsSourceView.GetOrCreate(System.Collections.IEnumerable) in ItemsSourceView.cs
    Avalonia.Controls.ItemsControl.OnPropertyChanged(Avalonia.AvaloniaPropertyChangedEventArgs) in ItemsControl.cs
    Avalonia.Animation.Animatable.OnPropertyChangedCore(Avalonia.AvaloniaPropertyChangedEventArgs) in Animatable.cs
    Avalonia.Controls.ItemsControl.Items.set(System.Collections.IEnumerable) in ItemsControl.cs
    Prism.Regions.ItemsControlRegionAdapter.Adapt(Prism.Regions.IRegion, Avalonia.Controls.ItemsControl) in ItemsControlRegionAdapter.cs
    Prism.Regions.RegionAdapterBase<T>.Initialize(T, string) in RegionAdapterBase.cs
    Prism.Regions.RegionAdapterBase<T>.Prism.Regions.IRegionAdapter.Initialize(object, string) in RegionAdapterBase.cs
    Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(Avalonia.AvaloniaObject, string) in DelayedRegionCreationBehavior.cs

References

@DamianSuess DamianSuess self-assigned this Feb 6, 2023
@DamianSuess DamianSuess added bug Something isn't working enhancement New feature or request labels Feb 6, 2023
@DamianSuess DamianSuess marked this pull request as draft February 7, 2023 01:09
@DamianSuess
Copy link
Collaborator Author

This item needs researched. Even adding IList to our class appears to be overkill.

Overall, this PR is blocking the release of Preview-5

@DamianSuess DamianSuess added the help wanted Extra attention is needed label Feb 7, 2023
…iew5 updates. `Prism.Regions.Behaviors.RegionCreationException: 'An exception occurred while creating a region with name 'ListRegion'. The exception was: System.ArgumentException: Collection implements INotifyCollectionChanged but not IList. (Parameter 'source')`
@DamianSuess DamianSuess marked this pull request as ready for review February 7, 2023 20:21
@DamianSuess
Copy link
Collaborator Author

DamianSuess commented Feb 7, 2023

Fixed issue by performing a cast expression on:

regionTarget.Items = region.Views as Avalonia.Collections.AvaloniaList<object>;

…mechanism after the MainWindow's `Show()` method
@DamianSuess DamianSuess added this to the Avalonia v11-Preview5 milestone Feb 7, 2023
@DamianSuess DamianSuess merged commit 67917c8 into develop Feb 7, 2023
@DamianSuess DamianSuess deleted the feature/v11prev5-PrismModules branch February 7, 2023 20:59
@DamianSuess DamianSuess changed the title v11-Prev 5 - After Upgrading Prism Module Fails To Register Region v11-Prev 5 - After Upgrading Prism Module Region Fails Inside of ItemsControl Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant