Closed malsabi closed 8 months ago
I couldn't reproduce duplicate command calls, can you share a minimal reproduction example?
After spending some more time observing the behavior, I've identified that the problem originates from the Picker control in MAUI. Specifically, if the SelectedItem property is set to a certain value, it unexpectedly resets to null.
This issue is similar to the one reported in dotnet/maui#14832. However, there's a key difference: in my case, the issue occurs within a ContentPage, not a Popup.
Given that the problem is not related to the SelectedValueChangedCommand, this issue can be considered irrelevant to the original concern and may be closed.
Yes, PickerField uses the default MAUI Picker inside InputField class, all the behaviors come from MAUI PickerField. I'll check the situation in the original issue and if there can be a workaround for now, I can share in here
Actually It was a mistake from me, I was setting SelectedItem before making sure ItemsSource is initialized completely. Whenever the ItemsSource is initialized it will set the SelectedItem to null. Also this applies to CollectionView. A Quote from Microsoft documentation
A Picker can be initialized to display a specific item by setting the SelectedIndex or SelectedItem properties. However, these properties must be set after initializing the ItemsSource collection.
When integrating PickerField with both the SelectedItem property and the SelectedValueChangedCommand, an unexpected behavior occurs upon modifying the SelectedItem within the ViewModel. Specifically, the SelectedValueChangedCommand is triggered twice under these conditions:
This issue significantly impacts functionality, as it results in the SelectedItem being reset to null, thereby losing its originally assigned value. This duplication and subsequent nullification are causing numerous problems in scenarios where the preservation of the SelectedItem's value is critical.