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

Using DataTemplate breaks ObservableCollection binding #15147

Open
Sebosek opened this issue May 18, 2023 · 1 comment
Open

Using DataTemplate breaks ObservableCollection binding #15147

Sebosek opened this issue May 18, 2023 · 1 comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-flex FlexLayout issues platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@Sebosek
Copy link

Sebosek commented May 18, 2023

Description

In the application I have AppContentView, it's a very small control, that inherits from ContentView and adds Title bindable property - that's it. I'm using it to show different content wrapped in the same visual style.
To switch between these views I have labels rendered by BindableLayout and collection binding and GestureRecognizer (in a real application I have my custom control, but let's keep it simple as it is in the reproducible sample).

<FlexLayout BindableLayout.ItemsSource="{Binding ContentViews}">
    <BindableLayout.ItemTemplate>
        <DataTemplate x:DataType="controls:AppContentView">
            <Label Text="{Binding Title}">
                <Label.GestureRecognizers>
                    <TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped" />
                </Label.GestureRecognizers>
            </Label>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</FlexLayout>

In the app, I have only two AppContentViews, one of them is an empty view and the first one contains an ObservableCollection of strings and a command to add a string to the collection.
Now here comes the important part! If I click on the button to add a string BEFORE switching the view, the string is added to the ObservableCollection as expected, but, once I switch a view and go back, the ObservableCollection binding is broken! BUT, only for ObservableCollection, the rest of the bindings work as expected!
However, if I use buttons instead of GestureRecognizer it works! (Which I obviously can't use, because I can't style buttons.)

I've tested it also in Windows and it works as expected (even though there is a significant delay in displaying new items), only the Android is completely broken. The iOS version I can't currently verify.

Steps to Reproduce

  1. Clone the sample
  2. Run it in Android emulator
  3. Click on "Add" button to add items to the collection
  4. Change a view by clicking on "Empty" label at the bottom of the screen
  5. Go back to "Bindings" screen by clicking on "Bindings" label at the bottom of the screen
  6. Click on "Add" button to add more items into the collection
  7. No more items aren't added to the collection - BUG
  8. Verify the rest of the binding by clicking on "Increase" and "Decrease" buttons

Link to public reproduction project repository

https://github.com/Sebosek/BrokenDataTemplate

Version with bug

7.0.81

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 (API 31)

Did you find any workaround?

No.

Relevant log output

No response

@Sebosek Sebosek added the t/bug Something isn't working label May 18, 2023
@Eilon Eilon added area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-flex FlexLayout issues labels Jun 20, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed platform/android 🤖 labels Jul 13, 2023
@XamlTest
Copy link
Collaborator

Verified this on Visual Studio Enterprise 17.7.0 Preview 3.0. Repro on Android 13.0-API33(.NET 7 and .NET 8), not repro on Windows 11 and iOS 16.4 with below Project:
BrokenDataTemplate.zip

.NET 7: Add button does not work after switching from "Empty" label.
Button NET7
.NET 8:: Add button does not work.
Button NET8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-flex FlexLayout issues platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants