AvaloniaCommunity / Prism.Avalonia

Prism framework support for Avalonia UI
https://www.nuget.org/packages/Prism.Avalonia/
MIT License
271 stars 36 forks source link

[Issue] Registered views don't show in ItemsControl region #101

Closed rmhw closed 7 months ago

rmhw commented 8 months ago

Description

Registered views don't display in an ItemsControl region

Environment

Severity (1-5)

3

Steps To Reproduce

  1. Designated an ItemsControl as a region <ItemsControl prism:RegionManager.RegionName="TestRegion" />
  2. Registered a view with the region regionManager.RegisterViewWithRegion("TestRegion", typeof(TestView1)); regionManager.RegisterViewWithRegion("TestRegion", typeof(TestView2));`
  3. Run the application - nothing appears in the ItemsControl
  4. Change the ItemsControl to a ContentControl - TestView1 is shown.

Expected Behavior

TestView1 and TestView2 should be displayed in the ItemsControl.

Additional context

Having stepped through the code, the issue seems to come from ItemsControlRegionAdapter, where the following line sets ItemsSource to null. regionTarget.ItemsSource = region.Views as Avalonia.Collections.AvaloniaList<object>;

rmhw commented 8 months ago

I've worked around this by implementing a callback approach based on https://github.com/DamianSuess/Learn.PrismAvaloniaOutlookish/blob/f6234acf7596e3e2c8dfa0ec72b2ed35c4295cda/source/SampleApp.Common/TabControlAdapter.cs, which seems to be working at first glance.

DamianSuess commented 7 months ago

@rmhw, from your implementation, could you provide an example for the Prism.Avalonia community? PR contributions are welcomed 👍

rmhw commented 7 months ago

@DamianSuess Thanks for coming back to me. Sure, happy to make a PR - are there any contributor guidelines I should be aware of?

DamianSuess commented 7 months ago

If you can add it to the Samples\SampleMvvmApp that would be great!

In upcoming releases (+9.x), I'd like to bring more behavior helpers as part of the main project. The reason this wasn't done sooner was due to concerns about having to support edge cases in other people's software.

Looking forward to your PR contribution, this will help teach others and be a nice asset to the project.

Thank you @rmhw

dhhunter commented 6 months ago

I ran into this problem just today using Prism.Avalonia 8.1.97.11000, any idea when the Release packages will be updated with the fixed ItemsControlRegionAdapter? Thank you all for your hard work on this great package!

Edit: I suppose their is really no hurry, it finally occurred to me that I just needed to remove the call to base.ConfigureRegionAdapterMappings so that I could successfully register the ItemsControlRegionAdapter from the sample! So far, so good! Thanks again!