SelectedValue is set to null on initialization
Hey there
I am quite new to Maui and I use your controls in some cases. I use a TabView and in the DataTemplate I have defined a Autocomplete control like that:
<editors:SfAutocomplete Grid.Row="3" Grid.Column="1"
SelectedValuePath="Id"
TextMemberPath="Art"
DisplayMemberPath="Art"
SelectionMode="Single"
SelectedValue="{Binding ProbenahmeArtId, Mode=Default}"
ItemsSource="{Binding AppContext.AlleProbenahmeArten, Source={RelativeSource AncestorType={x:Type viewModels:ProbeViewModel}}}"/>
When opening the view, the selection is always empty so I startet to debug and saw that 'ProbenahmeArtId' is set correctly but after the binding update from ItemsSource is is set to null. The callstack shows me, that its fired when init the view.
Is there a solution to change this incorrect behavior?
Thx and regards!
Same weird behavior if I use SfComboBox instead of SfAutocomplete. Maybe that helps to narrow down, what is wrong in my scenario.
Hi Günter Rudigier,
We have reviewed your query regarding the issue where the initial selection appears empty in the SfAutocomplete control. Based on your code snippet, we recommend setting the ItemsSource before defining the SelectedValuePath and SelectedValue bindings. This should resolve the issue where the selected item is not displayed initially.
Code:
<editors:SfAutocomplete Grid.Row="1"
TextMemberPath="Art"
DisplayMemberPath="Art"
SelectionMode="Single"
ItemsSource="{Binding AlleProbenahmeArten}"
SelectedValuePath="Id"
SelectedValue="{Binding ProbenahmeArtId}"/>
To assist you further, we have attached a sample demonstrating the suggested changes. Kindly review it and let us know if this resolves your issue or if further assistance is needed.
Regards,
Kamalesh P
Attachment: ComboBoxSample_d31f640f.zip
Hi there
Thx for your help and the example! I checked it and your solutions looks fine. I tried to change the order in my project but it did not work and then I found the reason why it is not working.
Problem is the binding of the ItemsSource.
ItemsSource="{Binding AppContext.AlleProbenahmeArten, Source={RelativeSource AncestorType={x:Type viewModels:ProbeViewModel}}}"
I load the data from main view model and not form the items view model and then the ItemsSource is always loaded later and the SelectedValue is set to null. Now I tried to load the ItemsSource directly from the items VM and then it is working as expected.
So my guess is, that Maui causes this issue because the binding is done, when the view is ready. Maybe you have a solution for that, because it makes no sense to populate the ItemsSource in every single item VM...
Regards!
Hi Günter Rudigier,
Thank you for your findings and update. Based on your input, we are currently investigating the issue on our end and will provide you with the details by March 19, 2025. We appreciate your patience until then.
Regards,
Kamalesh P
Hi Günter Rudigier,
We have addressed the reported issue "SelectedValue is set to null on Initialization" on our end. At present, a custom patch has been created for version 28.2.11 We have attached the NuGet files for your convenience.
Please note that we have created this patch for version 28.2.11 specifically to resolve the issue reported in this ticket. If you have received other patches for the same version for other products, please apply all patches in the order received.
Please clear the NuGet cache, before using the latest one and please refer to the below link for this
Please refer to the below KB to install the custom NuGet on a local machine,
Note: Kindly test the patch on your end and shares your confirmation. Based on your feedback, we will include the fix in our upcoming weekly release. If you are still facing the issue with the patch, kindly share a simple reproducible sample for better investigation.
Root Cause: The issue arises due to a delay in setting the ItemsSource, which causes the initially selected value to be set to null based on the ItemsSource.
Resolution: To resolve this issue, we have modified the code logic to update the selected value based on the availability of the ItemsSource.
Regards,
Kamalesh P
Attachment: Syncfusion.Maui.Inputs.28.2.11_e16243ec.zip
Hi Kamalesh
I am sorry for the late response, but I did not find time to test it...
I have updated the library but i get a exception and the app is crashing right after start. I am running it on Windows at the moment.
On Android it looks better and it seems to work fine...
Maybe you can find any issue...
Regards
Hi Günter,
Thanks for your update! Glad to hear that the reported issue is resolved on Android.
We have rechecked the patch on our end in Windows platform, and we did not encounter any exceptions or crashes. We kindly request you to ensure that all NuGet packages in your project are using the same version as the provided patch (28.2.11). Typically, such issues arise due to version mismatches between dependencies.
Please recheck this on your end, and if everything works fine, kindly confirm. Let us know if your need any further assistance.
Regards,
Kamalesh P
Did upgrade to your test version and double checked the other libs and it looks good to me, see screenshot:
I am using .NET 8, maybe thats the problem?
Hi Günter,
Thank you for your response.
We have tested the patch with a .NET 8 sample on the Windows platform and did not encounter any issues. To better understand and investigate the problem you are facing, we kindly request you to share a reproducible sample. Having a sample that demonstrates the issue will allow us to analyze it more effectively and provide you with a precise solution.
Looking forward to your response. Let us know if you need any further assistance.
Regards,
Kamalesh P
Hi,
I created a minimalistic example and the error is the same if I run it for Windows. On Android its fine!
I hope you can reproduce!
Regards!
Attachment: SfComboBox_67a18a65.zip
Hi Günter,
We have included a fix for the reported issue "SelectedValue is set to null on Initialization" in our latest weekly NuGet release, v29.1.35, which is now available for download (NuGet). Please get in touch with us if you require any further assistance; as always, we would be happy to help you.
Additionally, thank you for sharing the requested details. We have reviewed your sample with the patch, as well as the weekly NuGet, and we did not encounter the reported crash on our end. We tested it on both Windows 10 and 11. Therefore, we request you to test it with the latest Syncfusion NuGet. Please let us know if you are still facing any issues.
Regards,
Kamalesh P
I checked today with the latest version 29.1.38 and it is working fine now!
Thx and regards!
Hi Günter Rudigier,
You are welcome.
We are glad to know that the reported problem has been resolved. Please let us know if you require any further
assistance on this. We will be happy to assist you.
Regards,
Preethi R
- 13 Replies
- 3 Participants
-
GR Günter Rudigier
- Mar 12, 2025 09:19 AM UTC
- Apr 16, 2025 05:07 AM UTC