dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

CollectionView first Item fail to refresh binded value using a IValueConverter (Windows) #23891

Open elTRexx opened 1 month ago

elTRexx commented 1 month ago

Description

As explained in this SO post, I have 2 CollectionViews in my testing project 1) Standard one binded to an ObservableCollection of mocked viewmodel class encapsulating a simple observable string property 2) Another (just for testing purpose originally, not mvvm pattern) to reflect directly visually the change made to my model by the first one. In order to update the UI on inner child class property modification I use a custom ObservableCollection, named DeepObservableCollection (from this SO post). And to properly display any model item in this UI second CollectionViews, I use a IValueConverter that will grab the inner child class string property and return it.

The first one use Entry to edit the string on UI. I then binded a returnCommand on this entries to update associated model string value and performed the necessary binding to reflect it on the second one (the DeepObservableCollection).

The Bug is that editing the first entry of my first CollectionViews is never reflected back visually on the second CollectionViews (but via debugging Trace.Writeline I can assert the model has been updated as required). For other following entry no issue so far.

Diving into this, I found out that the associated converter, strangely (bug), is call 2 times on each entry except the first one who is never called (explaining why the modified model string value is not reflect back in UI).

The whole main code are in my SO post,

EDIT

but if you need it i can upload my solution to github if it facilitate it. Here is my testing project uploaded to github

Steps to Reproduce

  1. Create a new MAUI project
  2. According to my SO post, create the viewmodel and model classes, along with StringPOCOToStringConverter and DeepObservableCollection ones.
  3. or alternatively pull my project from github directly here
  4. Perform the correct Binding (I use community.toolkit.mvvm).
  5. Run in Windows Machine.
  6. In MAUI window edit any entry of the first CollectionView following by a Return command (Return keyboard press)
  7. See that all except the first item are reflected back on the second CollectionView
  8. Alternatively you can put a BreakPoint on the StringPOCOToStringConverter.Convert method, and note for witch value argument it is called when updating the second ObservableCollection child class property.

Link to public reproduction project repository

https://github.com/elTRexx/TestingDeepRefresh

Version with bug

9.0.61 SR6.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

10.0.19041.0

Did you find any workaround?

Instead of Binding to the parent class items and use converter on them, Binding to the child class instead (and changing converter accordingly) make it work on each entry (thanks to the answer I got on my SO post).

Relevant log output

> dotnet workload list

Bienvenue dans .NET 8.0 !
---------------------
Version du kit SDK : 8.0.303

ID de la charge de travail installée      Version de manifeste      Source de l’installation
--------------------------------------------------------------------------------------------
maccatalyst                               17.2.8053/8.0.100         VS 17.10.35122.118
ios                                       17.2.8053/8.0.100         VS 17.10.35122.118
android                                   34.0.95/8.0.100           VS 17.10.35122.118
maui-windows                              8.0.61/8.0.100            VS 17.10.35122.118
github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

elTRexx commented 1 month ago

Hi @elTRexx. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Just uploaded and linked in OP description my testing project to github. (https://github.com/elTRexx/TestingDeepRefresh)

ninachen03 commented 1 month ago

I can repro this issue at window platform on the latest 17.11.0 Preview 7.0( 8.0.80 & 8.0.71 & 8.0.60). image