I'm converting from Xamarin to .NET Maui and the using the SFNumericUpDown control in the .Net Maui toolkit. I do not want the Value Changed callback to get called when I set the value programmatically. In Xamarin I could set a guard variable when setting programmatically and check it in the callback to avoid executing the code. In the Maui version it appears the callback gets fired quite a while after the code returns so the callback code gets executed. Is this the normal mode in Maui or a bug? if so what it the best way to accomplish this?
Hi Doug,
Thank you for reaching out.
We understand you're experiencing unexpected behavior where the ValueChanged callback of the SfNumericUpDown control gets triggered even after programmatically updating the value, which differs from your Xamarin.Forms experience. Based on our testing, we were unable to reproduce this behavior—in our case, the callback either did not fire unexpectedly or fired immediately and predictably.
We’ve also attached a working sample for your reference. Please try it on your end and let us know if the issue is reproducible there.
To investigate further and provide an accurate solution, we kindly request the following:
This information will help us investigate further and provide a more accurate solution.
We look forward to your response.
Regards,
Kamalesh P
I see that you clear the guard variable (isProgramaticChange) in the callback. In Xamarin NumericUpDown it could be cleared immediately after setting the value as shown below. DotNet Maui controls can still be handled the same way. I can change to this model but will need a guard variable for each control. Thank you for the work around.
private void Button_Clicked(object sender, EventArgs e)
{
if(numeric != null)
{
isProgramaticChange = true;
numeric.Value = 100;
... set more controls
isProgramaticChange = false;
}
}
Hi
Doug,
Thank you for the clarification regarding your implementation. We now
understand that you're resetting the isProgrammaticChange flag immediately
after setting the value on the SfNumericUpDown control. However, as you've
observed, the ValueChanged event still gets triggered even when the flag is in
place.
This behavior occurs because the control handles the value update at the thread
level internally, which can cause the ValueChanged event to be invoked after
your method has returned—even when the flag is already reset.
To resolve this, we recommend resetting the flag asynchronously using await
Task.Yield();. This defers the flag reset until after the value update has
fully completed, avoiding any premature clearing that could lead to the
ValueChanged callback executing unexpectedly.
Code:
|
private async void UpdateFlagAsync() { await Task.Yield(); isProgrammaticChange = false; } |
We've tested this approach across all supported platforms and confirmed that it
prevents the ValueChanged event from triggering unintentionally during
programmatic updates.
Please review the attached modified sample and let us know if this solution
resolves your issue. If the issue persists, feel free to share your code so we
can further assist you.
Let us know if you need any further assistance.
Regards,
Kamalesh P
This works great! What I found was that with a more complicated page the value change callback is actually getting called multiple times for each control on the initial display of the page. This is why setting the flag in the callback did not work. See attached.
I also found that customizing the up down buttons as described in the documentation does not work on Android 14 and .net 8.0. I does work OK on iOS. This is also in the sample.
Hi Doug,
We’re glad to hear that the provided solution resolved your issue.
Query 1: Event Triggers Multiple Times
Regarding your latest observations and the attached sample, we’ve reviewed and tested the code. As you mentioned, the ValueChanged event is triggered multiple times during the initial loading of the page. Upon further analysis, we found that this behavior is related to the order in which the properties and event subscriptions are applied to the control.
Reason for Multiple Triggers
In your current setup:
Because AllowNull = false enforces a default value of 0, this leads to the control initializing with 0, then updating to 60, and finally to 1 — causing the ValueChanged event to be triggered multiple times.
We want to clarify that this behavior is expected in .NET MAUI, and we observed the same behavior using the standard .NET MAUI Entry control. We’ve included the relevant comparison and modified event order in the updated sample for your reference.
Recommended Fix
To reduce or eliminate unnecessary ValueChanged triggers during initialization, set the AllowNull and Value properties before subscribing to the ValueChanged event. This adjustment ensures the event only fires when truly needed and aligns with your expected behavior.
Query 2: Regarding Documentation for Up/Down Customization
We’ve reviewed your implementation for customizing the up/down buttons. Based on your code, it is consistent with what’s documented in our User Guide (UG), and we have confirmed that it works properly on both Android and iOS.
Please refer to this UG for guidance: [Up/Down Button Customization Documentation]
If you are experiencing any customization issues on Android, kindly share a video demo. This will help us better understand the issue and provide an accurate resolution.
Regards,
Prithis I.
Thanks for the explanation. I will make the changes in my code.
I tested the sample again and the droid version did not work in the simulator or a real device. See screen shot. The up down buttons worked but were not visible.
Here is a screenshot from a Samsung Droid V14 and .Net 8
Hi Doug,
We tested the sample on Android and confirmed the issue where the up/down icons were not rendering. Upon further investigation, we found that the required font file for the custom icons was missing and not registered in the MauiProgram.cs file.
To resolve this, we’ve added the necessary font file and registered it properly in MauiProgram. After making these changes, the icons now render correctly on Android devices, including Android 14.
Please check the modified sample attached below and let us know if this resolves the issue on your side as well.
Let us know if you need further assistance.
Code
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("MauiMaterialAssets.ttf", "MauiMaterialAssets");
});
Regards,
Kamalesh P