DataFormNumericItem not binding

Hello,

I am playing with SfDataForm, I am trying to bind numeric decimal to a model property but the value is not getting changing.
I have also tried to change the property type from decimal to float, still the same behavior.

<dataForm:SfDataForm x:Name="ReceiptItemDataForm"
AutoGenerateItems="False"
ValidationMode="PropertyChanged"
CommitMode="PropertyChanged"
LayoutType="TextInputLayout"
DataObject="{Binding SelectedReceiptItem}">
<dataForm:SfDataForm.Behaviors>
<behaviors1:DataFormBehavior
x:TypeArguments="receiptItems:ReceiptItemDto" />
</dataForm:SfDataForm.Behaviors>
<dataForm:SfDataForm.Items>
<dataForm:DataFormTextItem FieldName="Name" />
<dataForm:DataFormTextItem FieldName="Category" />
<dataForm:DataFormNumericItem
Culture="{x:Static sys:CultureInfo.InvariantCulture}"
AllowNull="False"
FieldName="Quantity" />
<dataForm:DataFormTextItem FieldName="Unit" />
<dataForm:DataFormNumericItem
Culture="{x:Static sys:CultureInfo.InvariantCulture}"
AllowNull="False"
FieldName="UnitPrice" />
<dataForm:DataFormNumericItem
Culture="{x:Static sys:CultureInfo.InvariantCulture}"
AllowNull="False"
FieldName="TotalPrice" />
</dataForm:SfDataForm.Items>
</dataForm:SfDataForm>


public class ReceiptItemDto
{
[Display(AutoGenerateField = false)] public Guid Id { get; set; }

[Required(AllowEmptyStrings = false, ErrorMessage = "Name should not be empty")]
[MinLength(3, ErrorMessage = "Item name must be at least 3 characters long.")]
public required string Name { get; set; }

[Required(ErrorMessage = "Quantity should not be empty")]
[DataType(DataType.Currency)]
public required float Quantity { get; set; }

[Required(AllowEmptyStrings = false, ErrorMessage = "Unit should not be empty")]
[MinLength(2, ErrorMessage = "Unit must be at least 3 characters long.")]
public required string Unit { get; set; }

[DataType(DataType.Currency)]
[Required(ErrorMessage = "Unit price should not be empty")]
public required float UnitPrice { get; set; }

[DataType(DataType.Currency)]
[Required(ErrorMessage = "Unit price should not be empty")]
public required float TotalPrice { get; set; }

[Required(AllowEmptyStrings = false, ErrorMessage = "Category should not be empty")]
[MinLength(3, ErrorMessage = "Category must be at least 3 characters long.")]
public required string Category { get; set; }

[Display(AutoGenerateField = false)] public required Guid ReceiptId { get; set; }
}


[RelayCommand]
private async Task SaveReceiptItemChangesAsync(SfDataForm form)
{
if (SelectedReceiptItem is null) return;
IsReceiptItemFromValid = form.Validate();
if (!IsReceiptItemFromValid)
{
return;
}
form.Commit();
SaveOrUpdateReceiptItemsCommand command = new()
{
ReceiptItemId = SelectedReceiptItem.Id,
Name = SelectedReceiptItem.Name,
Quantity = SelectedReceiptItem.Quantity,
Unit = SelectedReceiptItem.Unit,
UnitPrice = SelectedReceiptItem.UnitPrice,
TotalPrice = SelectedReceiptItem.TotalPrice,
Category = SelectedReceiptItem.Category,
ReceiptId = ReceiptId
};

await mediator.Send(command);
await Shell.Current.GoToAsync("..");
}


In this case Quantity, UnitPrice, TotalPrice​ are not getting the values updated.
I have tried setting the Culture also, as you can see in the above code sample.

Also changing the property type from float ​to int ​does not seems to produce any effect. The value is not getting updated.
For strings it works.

Using a built-in Entry ​component works:

<Entry Placeholder="0.0" Keyboard="Numeric"
Text="{Binding SelectedReceiptItem.Quantity,
Mode=TwoWay,
FallbackValue=0}">
</Entry>

5 Replies

MA Mihai Alexandru Dumitru February 7, 2025 03:53 PM UTC

It seems the problem is coming from the fact the the property is not getting updated when I am pressing the save button while keeping the input in focus.



VM Vidyalakshmi Mani Syncfusion Team February 12, 2025 02:56 PM UTC

Hi Mihai,


Thank you for reaching out to us. We have found and fixed the issue you reported, and the issue fix will be included in our weekly NuGet release on February 25, 2025. We will notify you once it is available. We appreciate your patience until then.


As a temporary workaround, you can set the ValueChangeMode of DataFormNumericItem (SfNumericEntry) to OnKeyFocus. Here’s an example of how to implement this:


 

this.ReceiptItemDataForm.ItemManager = new DataFormItemManagerEditorExt();

 

public class DataFormItemManagerEditorExt : DataFormItemManager

{

    public override void InitializeDataEditor(DataFormItem dataFormItem, View editor)

    {

        if (editor is SfNumericEntry numericEntry)

        {

            numericEntry.ValueChangeMode = ValueChangeMode.OnKeyFocus;

        }

    }

}

 


For your convenience, we’ve also attached a sample demonstrating this approach. Please let us know if you have any questions or need further assistance.


Regards,

Vidyalakshmi M.



Attachment: MAUIDataForm_7028d1c5.zip


MA Mihai Alexandru Dumitru February 13, 2025 12:35 AM UTC

Thanks, this seems to work.



VM Vidyalakshmi Mani Syncfusion Team February 13, 2025 12:08 PM UTC

Hi Mihai,


We'll keep you updated and let you know once the issue fix is included in the weekly NuGet. Thank you for your patience!


Regards,

Vidyalakshmi M.




VM Vidyalakshmi Mani Syncfusion Team March 5, 2025 07:05 AM UTC

Hi Mihai,


Regarding issue “DataFormNumericItem not binding ”:


We have fixed the reported issue and included the issue fix in our latest weekly NuGet release update version 28.2.9, which is available for download at nuget.org


Root cause: The issue occurs because SfNumericEntry has its default ValueChangeMode set to OnLostFocus. Clicking a button does not cause the entry field to lose focus, preventing the value from being committed.


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you require any further assistance.


Regards,

Vidyalakshmi M.



Loader.
Up arrow icon