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

CollectionViewHandler2 RelativeSource binding to AncestorType not working #26066

Open
rysbilinski opened this issue Nov 22, 2024 · 1 comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working

Comments

@rysbilinski
Copy link

Description

Using RelativeSource binding AncestorType doesn't seem to work using CollectionViewHandler2

Steps to Reproduce

  1. Add a collecitonview to a page, and bind a property in the itemtemplate to the PageModel using RelativeBinding source of AncestorType:
<CollectionView.ItemTemplate>
    <DataTemplate>
        <StackLayout Padding="10">
            <Label Text="{Binding .}" />
            <Button
                Command="{Binding ShowDialogCommand, Source={x:RelativeSource AncestorType={x:Type pm:RelativeSourceBindingPageModel}}}"
                CommandParameter="{Binding .}"
                Text="Show Dialog" />
        </StackLayout>
    </DataTemplate>
</CollectionView.ItemTemplate>
  1. Enable CollectionViewHandler2:
#if IOS || MACCATALYST
            builder.ConfigureMauiHandlers(handlers =>
            {
                handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
                handlers.AddHandler<Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls.Handlers.Items2.CarouselViewHandler2>();
            });
#endif
  1. run the app on iOS and you will see that the binding simply doesn't work
  2. disabling CollectionViewHandler2 resolves the issue

See the RelativeSourceBindingPage in the attached reproduction repository
CollectionViewHandler2Bugs/Pages/RelativeSourceBindingPage.xaml

Link to public reproduction project repository

https://github.com/rysbilinski/CollectionViewHandler2Bugs

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

If you use the normal CollectionViewHandler then the binding works as expected

       ```

builder
.UseMauiApp().ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.UseMauiCommunityToolkit();
//#if IOS || MACCATALYST
// builder.ConfigureMauiHandlers(handlers =>
// {
// handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
// handlers.AddHandler<Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls.Handlers.Items2.CarouselViewHandler2>();
// });
//#endif


### Relevant log output

```shell

@rysbilinski rysbilinski added the t/bug Something isn't working label Nov 22, 2024
@samhouts samhouts added platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Nov 22, 2024
@PureWeen
Copy link
Member

possibly related
#25195

@PureWeen PureWeen added this to the .NET 9 Servicing milestone Nov 22, 2024
@PureWeen PureWeen added the p/2 Work that is important, but is currently not scheduled for release label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants