问题
So I am consuming a Web Service and I have the value:
CustomersList with the list of customers.
When I bind the Data to my Grid like this:
<ContentPage.BindingContext>
<vm:ApiVewModel/>
</ContentPage.BindingContext>
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding CustomersList}">
</dxg:DataGridView>
I can see the Grid but I see only certain fields like OID and CategoryFPA. The other columns are shown but they are empty. While in the Json (response) they have a value.
Any idea of what is wrong? My Customers class is:
public class Customers : INotifyPropertyChanged {
public String Oid { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Code { get; set; }
public string AFM { get; set; }
public String Email { get; set; }
public string DOY { get; set; }
public string Occupation { get; set; }
public long CategoryFPA { get; set; }
private List<Customers> _CustomersList { get; set; }
public List<Customers> CustomersList
{
get
{
return _CustomersList;
}
set
{
if (value != _CustomersList)
{
_CustomersList = value;
NotifyPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
The code I am using to get the data and put it in CustomersList:
var content = await response.Content.ReadAsStringAsync();
var customersJson = Regex.Unescape(content.Substring(1, content.Length - 2));
var customers = JsonConvert.DeserializeObject<List<Customers>>(customersJson);
CustomersList = new List<Customers>(customers);
EDIT: I guess the json file and the binding are fine! The problem is with the Customers class which wraps the json file. But I passed it from jsontoc# and this is the class it generated for the wrapper. So what is the appropriate way to wrap the fields?
回答1:
So what is the appropriate way to wrap the fields?
Copy your Json data and the follow the stpes in your Visual Studio.
Visual Studio Menu> Edit> Paste Special> Paste As Json Classes. It would generate the correct Customers class you want.
来源:https://stackoverflow.com/questions/63506671/xamarinforms-datagridview-devexpress-doesnt-show-values-on-some-fields