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

Avalonia v11.0.0-preview4 #31

Merged
merged 16 commits into from
Feb 4, 2023
Merged

Avalonia v11.0.0-preview4 #31

merged 16 commits into from
Feb 4, 2023

Conversation

DamianSuess
Copy link
Collaborator

@DamianSuess DamianSuess commented Nov 27, 2022

Add support for Avalonia v11.0.0-preview4

Action Items

References

@DamianSuess DamianSuess added the enhancement New feature or request label Nov 27, 2022
@DamianSuess DamianSuess self-assigned this Nov 27, 2022
@OmidID
Copy link
Collaborator

OmidID commented Nov 28, 2022

@DamianSuess Great job. Is it ready to merge?

@DamianSuess
Copy link
Collaborator Author

DamianSuess commented Nov 28, 2022

Not yet, thanks for asking. Figured I'd make a PR marked as draft so you & others can see the live progress and provide feedback on any improvements.

@DamianSuess
Copy link
Collaborator Author

DamianSuess commented Nov 28, 2022

I encountered an interesting error in the SampleMvvmApp project after upgrading to Avalonia v11.0.0-pre4.

The DashboardView's ListBox.DataTemplate causes an exception to be thrown in Prism.Avalonia's RegionViewRegistry.OnContentRegistered(..) because the DataTemplate does not define a DataType of the object in the template. Odd, we never had to do this before.

Error Message:

An exception has occurred while trying to add a view to region 'ContentRegion'.
- The most likely causing exception was was: 'Prism.Ioc.ContainerResolutionException: An unexpected error occurred while resolving 'SampleMvvmApp.Views.DashboardView'
---> System.InvalidOperationException: DataTemplate inside of DataTemplates must have a DataType set. Set DataType property or use ItemTemplate with single template instead.

Considerations:

We could modify the OnContentRegistered(..) and RegisterViewWithRegion(..) methods inside of RegionViewRegistry to return a Success (bool) and Exception similar to Prism.Form's NavigationResult. However, having RegisterViewWithRegion return a value breaks compatibility with Prism.WPF, Prism.Forms, Prism.Uno, etc.

Another option, when users set x:CompileBindings="True" they will be informed of these hidden XAML errors at compile time, and their apps won't crash. Though this option works, it would be good for Prism.Avalonia to report

Any thoughts or other options?

App.xaml.cs

        protected override void OnInitialized()
        {
            var regionManager = Container.Resolve<IRegionManager>();

            // Error in missing `DataType` gets picked up inside here
            regionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(DashboardView));
            regionManager.RegisterViewWithRegion(RegionNames.SidebarRegion, typeof(SidebarView));
        }

DashboardView.xaml
Before - Error caused by missing DataType in DataTemplate.

      <ListBox Margin="2"
               VerticalAlignment="Bottom"
               Items="{Binding ListItems}"
               ScrollViewer.HorizontalScrollBarVisibility="Visible"
               ScrollViewer.VerticalScrollBarVisibility="Visible"
               SelectedIndex="{Binding ListItemSelected}"
               SelectionMode="Single">
        <ListBox.DataTemplates>
          <DataTemplate>
            <TextBlock Text="{Binding .}"
                       FontSize="10"
                       TextWrapping="NoWrap" />
          </DataTemplate>
        </ListBox.DataTemplates>

After - Successful:

<UserControl xmlns="https://github.com/avaloniaui"
             ...
             xmlns:system="clr-namespace:System;assembly=mscorlib">
        ...
        <ListBox.DataTemplates>
          <DataTemplate DataType="{x:Type system:String}">
            <TextBlock Text="{Binding .}"
                       FontSize="10"
                       TextWrapping="NoWrap" />
          </DataTemplate>
        </ListBox.DataTemplates>

@rabbitism
Copy link
Contributor

The DashboardView's ListBox.DataTemplate causes an exception to be thrown in Prism.Avalonia's RegionViewRegistry.OnContentRegistered(..) because the DataTemplate does not define a DataType of the object in the template. Odd, we never had to do this before.

I believe the change is from this PR
AvaloniaUI/Avalonia#8221

@DamianSuess
Copy link
Collaborator Author

DamianSuess commented Dec 6, 2022

@rabbitism, great find! I was digging through PRs & change docs trying to find this. Dong, you win the internet for the week 🚀

Though I like the strongly typed nature of defining the DataType in a DataTemplate, this new feature may become a surprise to some developers upgrading.

Also including AvaloniaUI/Avalonia#8203 as a reference

According to the PR's suggested error handling, it currently doesn't throw the exception during compile time. Only until x:CompileBindings="true" is set, other wise we get it at runtime.

@@ -33,7 +33,7 @@ public static AppBuilder BuildAvaloniaApp()
})
.With(new Win32PlatformOptions
{
EnableMultitouch = true,
//// EnableMultitouch = true, // Not supported in Avalonia v11.0.0-preview4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is always enabled now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @maxkatz6 for the heads up. I updated the code comment to reflect your note

@DamianSuess DamianSuess marked this pull request as ready for review January 24, 2023 01:00
@DamianSuess
Copy link
Collaborator Author

I fixe the ViewDiscovery sample to render, however, it is no longer auto-switching the views as it did w/ Avalonia v0.10.x. It appears that during the MainWindow's creation, it is not registering the Prism Region "ContentRegion" in time.

To fix some of ViewDiscovery's AXML errors, I switched to Lite Theme, enabled compiled bindings, and moved View registration to the App.xaml. Still, the initial issue persists.

Comment on lines +6 to +13
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />
<!--<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />-->
<PackageReference Include="Avalonia.LinuxFramebuffer" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0-preview4" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be the list of dependencies that will be referenced with the Prism.Avalonia nuget package.
If so, I believe this list is excessive.

Most likely, for the mvvm framework you most likely only need main "Avalonia" package.
Note, that I have used Prism a very little before in WPF, so I might miss some details.

  • Avalonia.Desktop - will block application to run only on Win, Mac and Lin. With the way how .NET dependencies work, this dependency unfortunately won't allow users to target Browser (WASM) projects.
  • Avalonia.Controls.DataGrid, Avalonia.Diagnostics and Avalonia.Markup.Xaml.Loader - these should be harmless in general, but also bloat application size, when they are not used (that's why Diagnostics also disable for the release in our templates).
  • Avalonia.LinuxFramebuffer - only makes sense if users want to target linux framebuffer, but should be harmless otherwise.
  • Avalonia.ReactiveUI - probably isn't needed here. If Prism uses System.Reactive, this dependency should be added manually (note, Avalonia doesn't reference System.Reactive anymore, starting with coming soon preview5)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these packages still are needed for the sample project though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxkatz6 in the next preview 5 release of this repo, I'll trim those down. You're right, we should only be referencing the bare minimum, most of them aren't being used.

Comment on lines +49 to +60
<ListBox.ItemTemplate>
<!--
OLD: <DataTemplate>
NEW: <DataTemplate DataType="{x:Type system:String}">
https://github.com/AvaloniaUI/Avalonia/pull/8221
-->
<DataTemplate DataType="{x:Type system:String}">
<TextBlock Text="{Binding .}"
FontSize="10"
TextWrapping="NoWrap" />
</DataTemplate>
</ListBox.DataTemplates>
</ListBox.ItemTemplate>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, you don't necessary need DataType, if you use ListBox.ItemTemplate instead ListBox.DataTemplates.
It won't cause any exceptions, as ListBox.ItemTemplate is way more specific and won't pollute children with the template.
Although, it's always a good idea to setup more strict types. Especially with x:CompileBindings.

@maxkatz6
Copy link

I fixe the ViewDiscovery sample to render, however, it is no longer auto-switching the views as it did w/ Avalonia v0.10.x. It appears that during the MainWindow's creation, it is not registering the Prism Region "ContentRegion" in time.

For this PR, can you try to switch to nightly builds? I remember there were issues with ContentControl which possibly can cause problems like this (note, I haven't debugged this issue).

Nightly builds, which should be shipped as preview5 in next weeks, some more breaking changes. But it also is expected to be last preview before release candidate.

More about nightly builds you can find here: https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed or bot comments like this AvaloniaUI/Avalonia#10058 (comment)

@DamianSuess
Copy link
Collaborator Author

@maxkatz6, you're the man! i'll give it a shot. Wow, i wasn't expecting such quick feedback. If we ever meet up at some conference, a round of drinks are on me 👍

@DamianSuess
Copy link
Collaborator Author

hello all, just a heads up on the slow down..
Though I prefer the keep work & personal life separate, I just want to let you all know for the past month I've been very ill and still recovering. No, it's not the c-word. Pneumonia hit really hard and took its toll.

When the spare time allows in between old man naps, I'll try and get out preview NuGet packages for you all to consume (Preview-4, and Nightly) as per MaxKatz's awesome suggestion. I apologize for the inconvenience

@DamianSuess
Copy link
Collaborator Author

Published v8.1.91.3-preview.11.4 to NuGet.org

@DamianSuess DamianSuess merged commit 14970c4 into master Feb 4, 2023
@DamianSuess DamianSuess deleted the feature/Avalonia-0.11pre4 branch February 4, 2023 01:52
@OmidID
Copy link
Collaborator

OmidID commented Feb 4, 2023

WOA. WONDERFUL. THANKSSSSSSS A LOT. GREAT JOB

@DamianSuess DamianSuess added this to the Avalonia v11.0-Preview milestone Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants