XamarinForms DataGridView(DevExpress)在某些字段上不显示值 [英] XamarinForms DataGridView (DevExpress) doesn't show values on some fields

查看:111
本文介绍了XamarinForms DataGridView(DevExpress)在某些字段上不显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用Web服务,并且我具有以下价值:

CustomersList和客户列表.

当我像这样将数据绑定到网格时:

 < ContentPage.BindingContext>< vm:ApiVewModel/></ContentPage.BindingContext>< dxg:DataGridView x:Name ="grid"ItemsSource =" {BindingCustomersList}"></dxg:DataGridView> 

我可以看到表格,但只能看到某些字段,例如OID和CategoryFPA.显示了其他列,但它们为空.在Json(响应)中,它们有一个值.

有什么问题的主意吗?我的客户类是:

 公共类客户:INotifyPropertyChanged {公共字符串Oid {get;放;}公共字符串名称{get;放;}公共字符串Title {get;放;}公共字符串代码{放;}公共字符串AFM {get;放;}公共字符串电子邮件{get;放;}公共字符串DOY {get;放;}公共字符串职业{get;放;}公共长CategoryFPA {get;放;}私人列表<客户>_CustomersList {get;放;}公开列表<客户>客户清单{得到{返回_CustomersList;}放{如果(值!= _CustomersList){_CustomersList =值;NotifyPropertyChanged();}}}公共事件PropertyChangedEventHandler PropertyChanged;受保护的void NotifyPropertyChanged([CallerMemberName]字符串propertyName ="){PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(propertyName));}} 

我用来获取数据并将其放入客户列表的代码:

  var content =等待响应.Content.ReadAsStringAsync();var customerJson = Regex.Unescape(content.Substring(1,content.Length-2));var customer = JsonConvert.DeserializeObject< List< Customers>>(customersJson);客户列表=新列表<客户>(客户); 

我想json文件和绑定很好!问题在于包装JSON文件的Customers类.但是我是从

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?

解决方案

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.

这篇关于XamarinForms DataGridView(DevExpress)在某些字段上不显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆