DataFormDropDownItem binding

Bonjour,

je rencontre un problème concernant le binding du DataFormDropDownItem. En effet, je voudrais effectuer le binding sur une ObservableCollection<Client> retourné par mon API et affiché la propriété Name.
Seulement lorsque je fais cela :

<ContentPage.Resources>
        <RessourceDictionary>
            <donnee: ClientViewModel x: Key = "client" />
        </ResourceDictionary>
    </ContentPage.Resources>

///Code

dataForm: DataFormDropDownItem Name = "Client" Editor = "DropDown" BindingContext = "{StaticResource client}" ItemsSource = "{Binding Clients}" DisplayMemberPath = "Nom" />

Rien ne s'affiche. Si je met un point d'arrêt, je vois bien mes clients dans Clients.
Je vois que cela fonctionne très bien avec une List<string> mais pas avec ma collection.

Une idée?

Merci d'avance.

8 Replies

KA Karthikraja Arumugam Syncfusion Team March 10, 2020 06:45 AM UTC

Hi Stephane, 
 
Thank you for contacting Syncfusion support. 
 
Based on the shared information we have checked the mentioned issue “DataFormDropDownItem’s ItemsSource is not set with complex type while creating custom items” and from your code we suspect that you haven’t set SelectedValuePath which is required for the complex type of DropDown to set and get the value from the respective property. 
 
Please refer the following code snippet to achieve your requirement, 
  <dataForm:DataFormDropDownItem Name="Client"  
                                               Editor="DropDown"  
                                               BindingContext="{StaticResource client}"  
                                               ItemsSource="{Binding Clients}"  
                                               DisplayMemberPath="Nom"  
                                               SelectedValuePath="Nom"/> 
 
You can also refer our UG documentation to know more about complex type of DropDown in DataForm, 
 
We hope this helps. Please let us know if you have any concern. 
 
Regards, 
Karthik Raja A 



ST Stephane March 10, 2020 07:01 PM UTC

Bonjour,

je vous remercie de votre réponse. Cependant, j'ai essayé comme vous me l'avez conseillé et cela ne fonctionne pas. Je continu de chercher mais je perd beaucoup de temps sur ce problème.

Je n'ai pas précisé, je travaille seulement pour un projet Android. 

De plus, j'utilise un DataObject pour le dataform complet et je cherche a utiliser un viewmodel différent pour le DropDownItem.

Une autre solution?

Merci d'avance.

Stéphane.


KA Karthikraja Arumugam Syncfusion Team March 11, 2020 01:19 PM UTC

Hi Stephane, 
 
Thank you for the update. 
 
We have checked the mentioned issue “DataFormDropDownItem’s ItemsSource is not set with complex type while creating custom items” and we are unable to replicate it, we have tested with different binding contexts for DataForm and DropDownItem and ItemsSource set properly. On initial loading there is no SelectedItem so the editor will be empty, you can select the items from DropDown list. We have attached tested sample and video, 
 
Link: DropDown 
 
We have tested with Syncfusion update version 17.4.0.55 and Xamarin.Forms version 4.5.0.356 
 
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 back with the following details, 
 
·       Device configuration details 
·       Parent layout and page of DataForm 
·       Service from which ItemsSource is populated (if any) 
 
It will be helpful for us to check on it and provide you the solution at the earliest.   
 
Regards, 
Karthik Raja A 



ST Stephane March 11, 2020 02:48 PM UTC

Bonjour,

Je vous remercie j'essaye ce soir.

Je vous donne des nouvelles des que possible.

Cordialement.

Stéphane


ST Stephane March 11, 2020 09:18 PM UTC

Bonjour,

j'ai bien essayé votre solution qui fonctionne et je vous en remercie.
Seulement, mon view model est mis a jour via une methode allant chercher les données sur mon API AspNet.Core :

public async Task GetClient()
        {
            Clients.Clear();
            var resp = await Connexion.GetData("Clients"); //Methode static utilisant system.net.http
            var client = JsonConvert.DeserializeObject<ObservableCollection<Client>>(resp);
            foreach (var j in client)
                Clients.Add(j); //Clients obtient bien chaque client.
        }

Mais aucune mise a jour ne ce fait sur le xaml.
Vous trouverez les screens en pièces jointes.
J'espère que l'on trouvera une solution.

Merci d'avance.

Stéphane.

Attachment: Pictures_e78c12c8.zip


KA Karthikraja Arumugam Syncfusion Team March 12, 2020 01:10 PM UTC

Hi Stephane, 
 
Thank you for the update. 
 
We have checked your requirement of loading DropDown ItemsSource using JSON data in async process and while using async process there may be delay and view will generate before data loaded, so to reflect the updated value in view we need to raise property changed notifier for the property after value change. In your case please raise property changed notifier for the Clients property in ClientViewModel. 
 
 
Please refer the following code snippet to achieve your requirement, 
public class ClientViewModel : INotifyPropertyChanged 
        private ObservableCollection<Client> clients; 
 
        public ObservableCollection<Client> Clients 
       
            get { return clients; } 
            set 
           
                clients = value; 
                this.RaiseOnPropertyChanged("Clients"); 
           
       
 
        public ClientViewModel() 
       
            Clients = new ObservableCollection<Client>(); 
            this.GetValue(); 
       
 
        public async Task GetClient() 
       
            Clients.Clear(); 
            HttpClient Connexion = new HttpClient(); 
            var resp = await Connexion.GetAsync(“url to fetch data”);  
            if (resp.IsSuccessStatusCode) 
           
                var content = await resp.Content.ReadAsStringAsync(); 
                var client = JsonConvert.DeserializeObject<ObservableCollection<Client>>(content); 
                var clientsDatata = new ObservableCollection<Client>(); 
                foreach (var j in client) 
                    clientsDatata.Add(j); 
                this.Clients = clientsDatata; 
           
       
 
        private async void GetValue() 
       
            await this.GetClient(); ; 
       
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        private void RaiseOnPropertyChanged(string propertyName) 
       
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
       
 
 
From your code we found that you are adding each item to the Clients property, this will not raise property changed event so add values to a temporary field and assign the value to Clients property as we have specified in the above code snippet.  
 
We have prepared a sample for your scenario, 
Sample link: DataFormXamarin 
 
We hope this helps. Please let us know if you have any concern. 
 
Regards, 
Karthik Raja A 



ST Stephane March 12, 2020 06:22 PM UTC

Bonjour,

Merci pour votre coopération et votre rapidité. Ça fonctionne bien comme cela en effet. Ce que je ne comprend pas, c'est que je n'ai pas à faire autant de chose pour d'autre view models que j'utilise pour une sfDataGrid par exemple.

Je le saurai pour la prochaine fois. Je vais pouvoir avancer maintenant sur la personnalisation du sfDataForm.

Merci encore :).


KA Karthikraja Arumugam Syncfusion Team March 13, 2020 11:35 AM UTC

Hi Stephane, 
 
Thank you for the update. 
 
We are glad to know that the provided information helped you to achieve your requirement. As we have mentioned in our previous update, DataForm generates views before ItemsSource set in ViewModel since there is a delay in data loading from web service so we have to raise notifier on value change to update the value. 
 
Please let us know if you would require any further assistance. We are always happy to help you out. 
 
Regards, 
Karthik Raja A 


Loader.
Up arrow icon