I have a dataform inside a popup which opens to view the details of a selected row. When I open the popup for the first time, the data of the selected item is correctly displayed, but on subsequent openings of the popup, the dataForm data is not updated, even if the content of the linked object has changed.
Here is the code:
<sfPopup:SfPopup x:Name="SettorePopup"
IsOpen="{Binding VisualizzaSettorePopup}">
<sfPopup:SfPopup.ContentTemplate>
<DataTemplate>
<sfDataForm:SfDataForm x:Name="contentDataForm"
DataObject="{Binding SettoreCorrente}" <-- Maybe the problem is here
AutoGenerateItems="False"
LayoutType="TextInputLayout"
ValidationMode="LostFocus">
<sfDataForm:SfDataForm.TextInputLayoutSettings>
<sfDataForm:TextInputLayoutSettings ContainerType="Outlined"
FocusedStrokeThickness="3"
ShowHelperText="True"/>
</sfDataForm:SfDataForm.TextInputLayoutSettings>
<sfDataForm:SfDataForm.Items>
<sfDataForm:DataFormTextItem FieldName="Codice"
IsReadOnly="True"/>
<sfDataForm:DataFormTextItem FieldName="Nome"/>
</sfDataForm:SfDataForm.Items>
</sfDataForm:SfDataForm>
</DataTemplate>
</sfPopup:SfPopup.ContentTemplate>
</sfPopup:SfPopup>
Hi Michele,
#Regarding SfDataForm not refresh data
We could not replicate the reported scenario from our end. We have prepared the sample with the given information and checked the sample from our side. Please refer to the tested sample in the attachment.
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us with the following details,
.
Share the issue replicated videos and steps.
Share the issue replicated sample.
It will be helpful for us to check on it and provide you with a solution as soon as possible.
Regards,
SaiGanesh Sakthivel
Hi SaiGanesh,
thanks for your suggestion.
I'm still facing the issue, so I appropriately modified the project you sent me so as to replicate the problem. As you can see, selecting a row of the collectionView always shows the detail of the row selected the first time. However, the popup contains a label whose value is correctly updated, so I don't know how to force the SfDataform to update.
I'm waiting for your reply.
Regards
Hi Michele,
We recommend calling the UpdateEditors method to update the runtime value of the DataObject when utilizing manual editors. Please refer to the following code snippet for your reference.
MainPage
|
<sfPopup:SfPopup x:Name="SettorePopup" ShowFooter="True" ShowCloseButton="True" HeightRequest="800" WidthRequest="800" IsOpen="{Binding ShowPopup}"> <sfPopup:SfPopup.ContentTemplate> <DataTemplate> <VerticalStackLayout Padding="20"> <Label Text="{Binding CurrentContactsInfo.Codice, StringFormat='Codice: {0}'}" TextColor="Black"/> <sfDataForm:SfDataForm x:Name="contentDataForm" DataObject="{Binding CurrentContactsInfo}" AutoGenerateItems="False" LayoutType="TextInputLayout" ValidationMode="LostFocus"> <sfDataForm:SfDataForm.TextInputLayoutSettings> <sfDataForm:TextInputLayoutSettings ContainerType="Outlined" FocusedStrokeThickness="3" ShowHelperText="True"/> </sfDataForm:SfDataForm.TextInputLayoutSettings> <sfDataForm:SfDataForm.Items> <sfDataForm:DataFormTextItem FieldName="Codice" IsReadOnly="True"/> <sfDataForm:DataFormTextItem FieldName="Nome"/> </sfDataForm:SfDataForm.Items> <sfDataForm:SfDataForm.Behaviors> <local:DataFormBehavior/> </sfDataForm:SfDataForm.Behaviors> </sfDataForm:SfDataForm> </VerticalStackLayout> </DataTemplate> </sfPopup:SfPopup.ContentTemplate> </sfPopup:SfPopup> |
DataFormBehavior Class
|
public class DataFormBehavior : Behavior<SfDataForm> { private SfDataForm? dataForm;
protected override void OnAttachedTo(SfDataForm bindable) { base.OnAttachedTo(bindable); this.dataForm = bindable; this.dataForm.PropertyChanged += DataForm_PropertyChanged; }
private void DataForm_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "DataObject") { if (dataForm?.DataObject != null) { foreach (var property in typeof(ContactsInfo).GetRuntimeProperties()) { dataForm.UpdateEditor(property.Name); } } } }
protected override void OnDetachingFrom(SfDataForm bindable) { base.OnDetachingFrom(bindable); if (this.dataForm != null) { this.dataForm.PropertyChanged -= DataForm_PropertyChanged; this.dataForm = null; } } } |
Please refer to the modified sample in the following attachment. Please let us know if you have any concerns.
Regards,
SaiGanesh Sakthivel
Thanks, now it works like a charm.
Hi Michele,
We are glad that your issue is resolved!! Please let us know if you need further assistance. As always, we are happy to help you out.
Regards,
Vidyalakshmi M.
hi, I have the same problem.
Only the first used data inside the form is shown and when changing the bound value it's not changing.
I'm using MVVM and the viewmodel doesnt know anything about the editor or the UpdateEditor-method.
Can you provide an example for this scenario, too?
I would say the form should update itself whenever the binding is updated...
Tobias
Hi Tobias,
Regarding query “First used data inside the form is shown and when changing the bound value it's not changing”
As of now, the MAUI SfDataForm
control will automatically update the data object value when changes are made
in the editor view. For dynamic model changes, you can utilize the
PropertyChanged event for the data object to update the editor.
By subscribing to the PropertyChanged event of
your data object, you can update the editor in response to dynamic changes in
your model.
Here’s a code snippet for guidance:
Behavior class:
|
public class DataFormBehavior : Behavior<SfDataForm> { private SfDataForm? dataForm;
protected override void OnAttachedTo(SfDataForm bindable) { base.OnAttachedTo(bindable); this.dataForm = bindable; this.dataForm.PropertyChanged += DataForm_PropertyChanged; }
private void DataForm_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "DataObject") { if (dataForm?.DataObject != null) { foreach (var property in typeof(ContactsInfo).GetRuntimeProperties()) { dataForm.UpdateEditor(property.Name); } } } }
protected override void OnDetachingFrom(SfDataForm bindable) { base.OnDetachingFrom(bindable); if (this.dataForm != null) { this.dataForm.PropertyChanged -= DataForm_PropertyChanged; this.dataForm = null; } } }
|
We have prepared sample demonstrating this approach. Please review the sample and let us know if you need any further assistance.
Regards,
Vidyalakshmi M.
great, thank you this works.
But I still dont know why we have to do this manually and why this is no default behavior from the dataform.
Is there a reason that it wouldt update the fields when we update the bound property?
Hi Tobias,
Regarding issue “Need to call the UpdateEditor method manually”
We have checked the reported issue from our end. We have logged an issue report for the same; we will fix this issue and include the issue fix in our weekly NuGet release update which is expected to be available by July 16, 2024. We appreciate your patience until then.
You can track the status of this report through the following
feedback link: Update-editor-value-when-changing-the-data-object-property-value
Note: The provided feedback link is private, and you need to log in to view this feedback.
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”
Regards,
Vidyalakshmi M.
Hi Tobias,
Regarding issue “Need to call the UpdateEditor method manually”
We have fixed the reported issue and included the issue fix in our latest weekly NuGet release update version 26.1.42, which is available for download at nuget.org. Please find attached the updated sample for your reference.
Root cause: The problem occurred because the data object, which uses the INotifyPropertyChanged interface, didn't trigger the property change event. As a result, the editor view was not updated to reflect the changes.
We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you require any further assistance.
Regards,
Vidyalakshmi M.